通过另一个程序(非外接程序)打开DTE解决方案 [英] Open DTE solution from another program (not add-in)

查看:100
本文介绍了通过另一个程序(非外接程序)打开DTE解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从命令行项目中修改解决方案并使用envdte工具?

Is it possible to modify a solution, and use envdte tools, from a command-line project ?

我有一个用于修改解决方案的加载项.但是...一百多个项目都需要进行更改...所以我想制作一个具有相同逻辑的c#程序,只对所有解决方案文件进行迭代.

I have an add-in that modifies a solution. But... the changes are required for over a hundred projects... So I'd like to make a c# program that has the same logic, only it iterates through all solution files.

加载项以

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

其中DTE2 application是从外接程序传递的...

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

如何获得相同的解决方案,然后查询项目... 从一个单独的程序中,那只会知道solutionPath?

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

是否可以打开解决方案,对其进行处理然后将其关闭-转到下一个解决方案?

Is it possible to open the solution, process it, and close it - to move on to the next solution ?

Microsoft提供了此示例 http ://msdn.microsoft.com/zh-CN/library/envdte._solution.open(v = vs.100).aspx

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

但是我不知道上下文中的dte是什么...

But I don't know what dte is in the context...

谢谢...

VS 2010

编辑:我做了以下答案所建议的事情. 使用链接稍作修改: http://msdn.microsoft.com/zh- us/library/ms228772(v = vs.100).aspx

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

谢谢

推荐答案

可以.您只需要使用COM CLSID for Visual Studio激活实例.下面是一个示例.它实际上创建了一个解决方案并向其中添加了两个项目,但是在打开现有解决方案时将应用相同的初始化.

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

一些警告:

  1. 注意COM线程模型.从控制台应用程序模板创建的代码就足够了:

  1. Mind the COM threading model. The code created from the console app template is sufficient:

[STAThread]
static void Main()

  • 如果您安装了功能强大的VS扩展程序(如ReSharper),则最好不要挂起它,因为VS自动化不需要它. ReSharper拥有VS命令来控制它.

  • If you have a powerful VS extension like ReSharper installed, you might be better off suspending it if you don't need it for the VS automation. ReSharper had VS commands that control 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);
        }
    

  • 这篇关于通过另一个程序(非外接程序)打开DTE解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆