Considerations for unloading and reloading nested projects

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

When you implement nested project types, you must perform additional steps when you unload and reload the projects. To correctly notify listeners to solution events, you must correctly raise the OnBeforeUnloadProject and OnAfterLoadProject events.

One reason to raise these events is for source code control (SCC). You don't want SCC to delete the items from the server and then add them back as new if there's a Get operation from SCC. In that case, a new file would be loaded out of SCC. You'd have to unload and reload all the files in case they're different.

Source code control calls ReloadItem. Implement the IVsFireSolutionEvents interface to call OnBeforeUnloadProject and OnAfterLoadProject to delete the project and re-create it. When you implement the interface in this way, SCC is informed that the project was temporarily deleted and added again. Therefore, SCC doesn't operate on the project as if the project was actually deleted and re-added.

Reload projects

To support reloading of nested projects, you implement the ReloadItem method. In your implementation of ReloadItem, you close the nested projects and then re-create them.

Typically when a project is reloaded, the IDE raises the OnBeforeUnloadProject and OnAfterLoadProject events. However, for nested projects that are deleted and reloaded, the parent project initiates the process, not the IDE. Because the parent project doesn't raise solution events, and the IDE has no information about the initialization of the process, the events aren't raised.

To handle this process, the parent project calls QueryInterface on the IVsFireSolutionEvents interface. IVsFireSolutionEvents has functions that tell the IDE to raise the OnBeforeUnloadProject event to unload the nested project, and then raise the OnAfterLoadProject event to reload the same project.

See also