How to programmatically update / reload a VS project after changing a base file?

I am developing a Visual Studio package, and I wrote code that will make the file in Solution Explorer dependent on another file.

This means that it gives them the same relationship as the code files or the designer files, where they appear in the parent file with plus / minus.

+ MainForm.cs


- MainForm.cs
   MainForm.Designer.cs
   MainForm.resx

The code I wrote successfully and correctly modifies the main project file, however, this change is not reflected in the Solution Explorer until the project is closed and reopened.

I am looking for some code that will update or reload the project so that the changes are immediately displayed in the solution explorer.

Additional Information...

Here is the sudo code that demonstrates the mechanism by which I create the dependent file.

IVsBuildPropertyStorage vsBuildPropertyStorage = GetBuildPropertyStorage();
vsBuildPropertyStorage.SetItemAttribute(projectItemIdentifier, "DependentUpon", parentFileName);

, , .

project.Save();
VSProject obj = project.Object as VSProject;
obj.Refresh();
+5
1

AFAIK - Solution Explorer:

EnvDTE.DTE dte = ...;

string solutionName = Path.GetFileNameWithoutExtension(dte.Solution.FullName);
string projectName = project.Name;

dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate();
((DTE2)dte).ToolWindows.SolutionExplorer.GetItem(solutionName + @"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect);

dte.ExecuteCommand("Project.UnloadProject");
dte.ExecuteCommand("Project.ReloadProject");

, , "Project.UnloadProject".

+8

All Articles