How to use DTE in PowerShell?

前端 未结 3 1053
一整个雨季
一整个雨季 2021-02-20 02:02

I am trying to use PowerShell to automate the process of creating an n-tier solution based on a seed (think EDMX file or DbContext) configuration. I want to be able to open a sk

3条回答
  •  天涯浪人
    2021-02-20 02:41

    I found a simple answer by playing with the idea in ISE for a little while.

    Basically, the call to GetActiveObject returns a COM object, which can be used directly in PowerShell. After executing LoadDTELibs, you can get an instance of DTE by calling GetActiveObject and then refer to the result directly.

    So...

    PS> $dte = [System.Runtime.InteropServices.Marshal]::GetActiveObject("VisualStudio.DTE.11.0")
    

    Then:

    PS> $dte.solution.Create("D:\Testing", "Acme.sln")
    PS> $dte.solution.SaveAs("D:\Testing\Acme.sln")
    

    I'm not 100% sure, because I don't know PowerShell or COM all that well, but I think you don't really have to worry about releasing the COM instance.

提交回复
热议问题