1

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

4

2 回答 2

0

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

于 2012-09-13T13:05:59.920 回答
0

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

它的基本要点:

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 社区扩展)

于 2018-03-13T18:10:01.163 回答