Is it possible to hide the window generated when creating a project with Visual studio sdk?

216 views Asked by At

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

1

There are 1 answers

0
piertoni On

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=