During nuget install I give the user a command they can run. This command basically scans some files and creates some code templates and then inserts them into the current project. This works just fine - except for the fact that Solution Explorer does not update its tree view with the new files. I know this works because I can unload and reload the project file and the files are there.

In case it helps, here is the code I use to add the files to the project - the second function is what the user actually calls.

This code causes a funny dialog to pop up - "The project has been modified on disk - please reload" - and hopefully the user will reload, and then the files show up correctly... But it would be nice to avoid that and just have the script cause whatever is needed to happen. Perhaps I have to figure out how to unload and re-load the project?

What do I need to do to force solution explorer to update? Many thanks!

1 Answer
1

By using the MSBuild project you are bypassing Visual Studio and directly updating the MSBuild project file on disk. The easiest way to get Visual Studio to update the Solutions Explorer window is to use the Visual Studio project object instead which you get from the Get-Project command.

Below is a simple example which adds a file to the solution and changes its ItemType to be ROOTFileDataModel. The example assumes you have a packages.config file in your project's root directory which is not currently added to the project so it is not showing in Solution Explorer initially.

First, sorry I didn't see this until today! I must have missed the email, and I missed the webpage notification icon. My Bad. Second, ok - like this - so one completely avoids the MSProject - and what you said makes sense. I'll try the modifications and get back to you if it works!
–
GordonJan 31 '12 at 0:50