使用Visual Studio SDK创建项目时,是否可以隐藏生成的窗口?

发布于 2025-02-07 04:23:15 字数 1848 浏览 0 评论 0原文

我目前正在尝试使用C#中的Visual Studio SDK创建一个Visual Studio项目,以下步骤:

  • 首先,我使用DTE界面打开Visual Studio,
  • 然后创建一个新目录
  • ,然后我创建一个解决方案文件,
  • 最后我在使用模板的解决方案

以下是下面的代码:

       //Load DTE           
        Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.16.0");
        EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(t);                  

        //Hide UI            
        dte.SuppressUI = true;
        dte.MainWindow.Visible = false;            

        //Create new directory           
        if (Directory.Exists(@"C:\Temp\SolutionFolder"))
            Directory.Delete(@"C:\Temp\SolutionFolder", true);
        Directory.CreateDirectory(@"C:\Temp\SolutionFolder");
        Directory.CreateDirectory(@"C:\Temp\SolutionFolder\SolutionTemp");

        //Create solution            
        dynamic solution = dte.Solution;
        solution.Create(@"C:\Temp\SolutionFolder", "SolutionTemp");
        solution.SaveAs(@"C:\Temp\SolutionFolder\SolutionTemp\MySolutionTemp.sln");

        //Create project with template           
        string template = @"C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj"; //path to project template
        dynamic project = solution.AddFromTemplate(template, @"C:\Temp\SolutionFolder\SolutionTemp", "MyTmpProject");         

一切正常,但是我在创建项目时出现的窗口下方,但我希望它被隐藏。有人知道如何隐藏“项目创建”窗口?

ps:我正在创建的项目是一个twincat项目( https://www.beckhoff.com/fr-fr/products/automation/automation/twincat/ )是基于Visual Studio的IDE,但没有任何差异。

谢谢,

伊曼纽尔

I am currently trying to create a visual studio project with the visual studio sdk in C# following those steps :

  • First I am using the DTE interface to open Visual studio
  • Then I create a new directory
  • Then I create a solution file
  • Finally I create the project in the solution using a template

Here is the code below :

       //Load DTE           
        Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.16.0");
        EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(t);                  

        //Hide UI            
        dte.SuppressUI = true;
        dte.MainWindow.Visible = false;            

        //Create new directory           
        if (Directory.Exists(@"C:\Temp\SolutionFolder"))
            Directory.Delete(@"C:\Temp\SolutionFolder", true);
        Directory.CreateDirectory(@"C:\Temp\SolutionFolder");
        Directory.CreateDirectory(@"C:\Temp\SolutionFolder\SolutionTemp");

        //Create solution            
        dynamic solution = dte.Solution;
        solution.Create(@"C:\Temp\SolutionFolder", "SolutionTemp");
        solution.SaveAs(@"C:\Temp\SolutionFolder\SolutionTemp\MySolutionTemp.sln");

        //Create project with template           
        string template = @"C:\TwinCAT\3.1\Components\Base\PrjTemplate\TwinCAT Project.tsproj"; //path to project template
        dynamic project = solution.AddFromTemplate(template, @"C:\Temp\SolutionFolder\SolutionTemp", "MyTmpProject");         

Everything works fine but I have the window below that appears when i create my project but I want it to be hidden. Does anyone know how to hide the "project creation" window ?

Project creation window

PS : The project I am creating is a Twincat project (https://www.beckhoff.com/fr-fr/products/automation/twincat/) that is an IDE based on visual studio but it doesn't make any differences.

Thanks,

Emmanuel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月静好 2025-02-14 04:23:15

您尝试了以下内容吗?

var settings = dte.GetObject("TcAutomationSettings");
settings.SilentMode = true;

官方文件说:

尽管Visual Studio DTE命令
在大多数用例中,“ dte.visible = true/fals”似乎足够
twincat自动化接口引入了新的静音模式开关,
自Twincat 3.1构建4020.0及以上以来就可以使用。

在:

Did you tried the following?

var settings = dte.GetObject("TcAutomationSettings");
settings.SilentMode = true;

The official documentation says:

Although the Visual Studio DTE command
“dte.Visible = true/false” may seem sufficient in most use cases, the
TwinCAT Automation Interface introduces a new Silent Mode switch,
which is available since TwinCAT 3.1 Build 4020.0 and above.

Check at: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_automationinterface/2489025803.html&id=

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文