HOWTO: Reopen the currently loaded solution from a VS Extension


Suppose you are developing user property sheets in your Visual C++ project. Dealing with the Property Manager is really troublesome, so you start to develop a VS extension. The VS entension manages which property sheets to import and edits property sheets.

You encounter a problem. If you edit a property sheet outside the IDE, the IDE will not automatically reload the property sheet and therefore such changes will not be reflected in the IDE. There seems to be no API for reloading property sheets. Removing the property sheet and re-adding it does not work either; property sheets seem to be cached somewhere.

In order to have the IDE reload property sheets, the only workaround I have found is reopening the entire solution. Let's do it.


Code Fragment

private void MenuItemCallback(object sender, EventArgs e)
    // Obtain the SVsSolution service object.
    var solutionService =
        this.ServiceProvider.GetService(typeof(SVsSolution)) as IVsSolution;

    // Check if there exists an open solution.
    object isSolutionOpen;
        out isSolutionOpen);
    if (!(bool)isSolutionOpen)

    // Retrieve the information on the open solution.
    // Full path to the directory cotaining the .sln file
    string solutionDirectory;   
    // Full path to the .sln file
    string solutionFile;
    // Full path to the .suo file
    string userOptsFile;
        out solutionDirectory,
        out solutionFile,
        out userOptsFile);

    // Close the entire solution. (pHier == null, docCookie == 0)
        // Prompt the user whether to save unsaved changes.

    // Reopen the solution.
    solutionService.OpenSolutionFile(0, solutionFile);