Open the DTE solution from another program (not add-in)

Can I change the solution and use the envdte tools from the command line project?

I have an add-in that modifies the solution. But ... changes are required for more than a hundred projects ... Therefore, I would like to make a C # program that has the same logic, only it iterates through all the solution files.

Add-in starts with

EnvDTE.Solution solution = (EnvDTE.Solution)application.Solution; 

where the DTE2 application is passed from the add-in ...

How can I get the same solution, which I then request for projects ... From a separate program that will know only the Path solution?

Is it possible to open a solution, process it and close it - go to the next solution?

Microsoft gives this example http://msdn.microsoft.com/en-us/library/envdte._solution.open(v=vs.100).aspx

But I do not know what dte is in context ...

Thanks...

VS 2010

edit: I did what it offers below. Slightly modified using the link: http://msdn.microsoft.com/en-us/library/ms228772(v=vs.100).aspx

thanks

+3
source share
1 answer

Yes, you can. You just need to activate the instance using COM CLSID for Visual Studio. The following is an example. It actually creates a solution and adds two projects to it, but when opening an existing solution, the same initialization is applied.

A few caveats:

  • Remember the COM streaming model. The code generated from the console application template is sufficient:

     [STAThread] static void Main() 
  • If you have a powerful VS extension, such as ReSharper, you might be better off pausing it if you do not need it to automate VS. ReSharper had VS teams that run it.

      Console.WriteLine("Opening Visual Studio"); var dte = (DTE)Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.DTE.10.0",true),true); Console.WriteLine("Suspending Resharper"); dte.ExecuteCommand("ReSharper_Suspend"); Console.WriteLine("Working with {0}, {1} edition", dte.FullName, dte.Edition); dte.SuppressUI = true; dte.UserControl = false; foreach (var solution in mySolutionInfoList) { try { dte.Solution.Create(solution.directory, solution.name); dte.Solution.AddFromTemplate(csharpTemplatePath, solution.directory + "ClassLibrary1", "ClassLibrary1"); dte.Solution.AddFromTemplate(vcTemplatePath, solution.directory + "Win32Dll", "Win32Dll"); Directory.CreateDirectory(solution.directory); // ensure directory exists. Otherwise, user will be asked for save location, regardless of SupressUI value dte.Solution.Close(true); Console.WriteLine(); } catch (Exception e) { Console.Error.WriteLine(e); } } Console.WriteLine("Resuming Resharper"); dte.ExecuteCommand("ReSharper_Resume"); try { dte.Quit(); } catch (Exception e) { Console.Error.WriteLine(e); } 
+6
source

Source: https://habr.com/ru/post/1486086/


All Articles