【问题标题】:How to add bunch of external tools into Visual Studio IDE using Powershell command?如何使用 Powershell 命令将一堆外部工具添加到 Visual Studio IDE 中?
【发布时间】:2018-03-14 06:28:16
【问题描述】:

我可以通过手动使用外部工具来添加第三方工具 - 这在 Visual Studio IDE 中可用。但我的要求是,需要通过执行 powershell 脚本来添加更多工具。这可能吗?

【问题讨论】:

    标签: powershell visual-studio-extensions


    【解决方案1】:

    是的,您可以使用 StudioShell 来处理 Visual Studio 的 DTE 对象。有关示例,请参阅 herehere

    【讨论】:

      【解决方案2】:

      您也可以使用导出的 xml 文件来执行此操作,或者只是在您的 powershell 脚本中创建,就像 here 所做的那样

      它的基本要点:

      param($installPath, $toolsPath, $package, $project)
      
      # Determine fully qualified path to a temp file
      $fileName = [System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString() + ".vssettings"; 
      
      # Create User Settings file:
      '<UserSettings>
          <ApplicationIdentity version="9.0"/>
          <ToolsOptions/>
          <Category name="Environment_Group" RegisteredName="Environment_Group">
              <Category name="Environment_ExternalTools" Category="{E8FAE9E8-FBA2-4474-B134-AB0FFCFB291D}" Package="{DA9FB551-C724-11d0-AE1F-00A0C90FFFC3}" RegisteredName="Environment_ExternalTools" PackageName="Visual Studio Environment Package">
                  <PropertyValue name="Launch Powershell.Command">powershell.exe</PropertyValue>
                  <PropertyValue name="Launch Powershell.Arguments">"&amp; ''$(ProjectDir)\Myscript.ps1''"</PropertyValue>
                  <PropertyValue name="Launch Powershell.InitialDirectory">"$(ProjectDir)"</PropertyValue>
                  <PropertyValue name="Launch Powershell.SourceKeyName"/>
                  <PropertyValue name="Launch Powershell.UseOutputWindow">true</PropertyValue>
                  <PropertyValue name="Launch Powershell.PromptForArguments">false</PropertyValue>
                  <PropertyValue name="Launch Powershell.CloseOnExit">true</PropertyValue>
                  <PropertyValue name="Launch Powershell.IsGUIapp">false</PropertyValue>
                  <PropertyValue name="Launch Powershell.SaveAllDocs">true</PropertyValue>
                  <PropertyValue name="Launch Powershell.UseTaskList">false</PropertyValue>
                  <PropertyValue name="Launch Powershell.Unicode">false</PropertyValue>
                  <PropertyValue name="Launch Powershell.Package">{00000000-0000-0000-0000-000000000000}</PropertyValue>
                  <PropertyValue name="Launch Powershell.NameID">0</PropertyValue>
                  <PropertyValue name="ToolNames">Launch Powershell</PropertyValue>
              </Category>
          </Category>
      </UserSettings>' >> $fileName
      
      
      # Perform the import of the custom tool
      $project.DTE.ExecuteCommand("Tools.ImportandExportSettings", "/import:""$fileName""");
      
      "--Remove file"
      Remove-Item -path $fileName
      

      注意:要使用 Visual Studio DTE,您需要使用第三方扩展,例如 PSCX(PowerShell 社区扩展)

      【讨论】:

      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
      • @JasonAller 添加了主脚本内容
      猜你喜欢
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      相关资源
      最近更新 更多