Rebooting uploaded projects in EnvDTE

I listed all the projects in my solution using EnvDTE, but found an error in my code: I cannot get projects that are unloaded.

I found a way to skip unloaded projects:

if (string.Compare(EnvDTE.Constants.vsProjectKindUnmodeled, project.Kind, System.StringComparison.OrdinalIgnoreCase) == 0) continue; 

This way my code does not crash, but I cannot load the missing projects through the code as they already exist.

How to load uploaded projects into the solution?

I tried:

 project.DTE.ExecuteCommand("Project.ReloadProject"); 

And the error turned out:

System.Runtime.InteropServices.COMException (...): The "Project.ReloadProject" command is not available.

So, I tried to somehow get

 application.DTE.ExecuteCommand("Project.ReloadProject"); 

But before that, from all the places that I was looking for in NET, I have to pre-select the project in the solution - and for this I need project.Name (which I have) and the path that I do not, t (in each example, which I found, it is assumed that the solution path is the same as the path to the project, which is unlikely in the general situation).

+6
source share
1 answer

The Visual Studio SDK is apparently the way to do this.

 var dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE"); Microsoft.VisualStudio.Shell.Interop.IVsUIHierarchyWindow hierarchy; ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte); IVsSolution sol = (IVsSolution)sp.GetService(typeof(SVsSolution)); foreach (ProjInfo info in GetProjectInfo(sol)) { info.Dump(); } //from http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/60fdd7b4-2247-4c18-b1da-301390edabf3/ static IEnumerable<ProjInfo> GetProjectInfo(IVsSolution sol) { Guid ignored = Guid.Empty; IEnumHierarchies hierEnum; if (ErrorHandler.Failed(sol.GetProjectEnum((int)__VSENUMPROJFLAGS.EPF_ALLPROJECTS, ref ignored, out hierEnum))) { yield break; } IVsHierarchy[] hier = new IVsHierarchy[1]; uint fetched; while ((hierEnum.Next((uint)hier.Length, hier, out fetched) == VSConstants.S_OK) && (fetched == hier.Length)) { int res = (int)VSConstants.S_OK; Guid projGuid; if (ErrorHandler.Failed(res = sol.GetGuidOfProject(hier[0], out projGuid))) { Debug.Fail(String.Format("IVsolution::GetGuidOfProject returned 0x{0:X}.", res)); continue; } string uniqueName; if (ErrorHandler.Failed(res = sol.GetUniqueNameOfProject(hier[0], out uniqueName))) { Debug.Fail(String.Format("IVsolution::GetUniqueNameOfProject returned 0x{0:X}.", res)); continue; } if( System.IO.Path.GetInvalidPathChars().Any (p =>uniqueName.Contains(p) )) { uniqueName.Dump("invalid filename found"); yield return new ProjInfo(projGuid,uniqueName); } else { yield return new ProjInfo(projGuid, Path.GetFileName(uniqueName).BeforeOrSelf("{")); } } } 

got most of http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/60fdd7b4-2247-4c18-b1da-301390edabf3/

+4
source

All Articles