Working with documents, project files and text views

Skip to end of metadata
Go to start of metadata

Project Model

ReSharper API for Visual Studio project model resides in JetBrains.ReSharper.ProjectModel namespace.

VS projects, solutions and their constitutients are represented instances of various interfaces all inheriting from JetBrains.ReSharper.ProjectModel.ProjectModelElement. Among inheritors from ProjectModelElement are ISolution, IProject, IProjectFile etc.

To start working with project model, you usually query yours action data context for DataConstants.SOLUTION for the current VS solution. The value you will get is an instance of ISolution interface. Starting from ISolution, you can query for projects, folders and files, examine their various properties etc.

If your action must work on selected element of project model, query your data context on DataConstants.PROJECT_MODEL_ELEMENT or DataConstants.PROJECT_MODEL_ELEMENTS, obtaining a IProjectModelElement. In text editor this will give you IProjectFile for edited file, in Solution Explorer you get selected items &c.


All read access to project model should be done under read lock.


ReSharper works with text of files through JetBrains.ReSharper.Editor.IDocument interface. This interface provides methods for reading and modifying text, and events that you can subscribe to if you want to listen to document changes.

To obtain a document for a specific IProjectFile you should query a DocumentManager:

DocumentManager handles linking documents with Visual Studio documents, saving and loading documents from disk etc.

You can also create document directly from text. Use JetBrains.ReSharper.Editor.DocumentFactory to do so. This document will not be associeated with any project file.

Modifying documents and project model

Under construction


JetBrains.ReSharper.ProjectModel.dll – Project Model APIs
JetBrains.ReSharper.DocumentModel.dll – IDocument and DocumentFactory
JetBrains.ReSharper.DocumentManager.dll – DocumentManager, linking project model and document model

Samples and power toys

The license could not be verified: There is no license certificate installed for CustomWare Linking Plugin for Confluence.

  • No labels