用于自动添加 Visual Studio“外部工具..."的 PowerShell 脚本菜单选项? [英] PowerShell script to auto-add Visual Studio "External Tools..." menu options?

查看:51
本文介绍了用于自动添加 Visual Studio“外部工具..."的 PowerShell 脚本菜单选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 Nuget 来管理我们的内部工具链并安装一些 PowerShell 脚本,我们目前通过自定义的外部工具..."菜单选项手动将这些脚本包含在 Visual Studio 中.

We use Nuget to manage our internal toolchain and installing some PowerShell scripts, which we currently manually include in Visual Studio via custom "External Tools..." menu options.

如果有一个 PowerShell 脚本可以自动添加通常需要外部工具..."对话框的菜单选项,我会喜欢它.是否有 API 可以执行此操作?

I would LOVE it if there was a PowerShell Script to automatically add menu options that normally require the "External Tools..." dialog. Is there an API to do this?

我已经编写了大部分 Dev On-boarding 流程来自动配置开发机器,除了一些像这样的怪事.

I have scripted out most of our Dev On-boarding process to automagically configure dev machines, save for a few oddities like this.

任何想法表示赞赏.

推荐答案

这是可能的.

在可以访问 DTE 对象的 NuGet 包的 init.ps1 文件中,可以从包含用户设置配置的动态创建的文件中导入新工具,然后在用户设置完成后删除该文件进口.

In the NuGet package's init.ps1 file, which has access to the DTE object, a new tool can be imported from a dynamically created file containing User Settings configuration that's then deleted after the user settings are imported.

这是一个执行导入的命令示例.该示例启动 Powershell,在项目的根目录中执行脚本.请注意,我使用 VS v9.0 以获得最大的向后兼容性,但可以仅导出 v15.0(或更新版本)中的现有工具菜单配置,并相应地替换下面文件中的内容.

Here's an example of a command to do imports. The example launches Powershell, executing a script in the root directory of a project. Note that I've used VS v9.0 for greatest backwards-compatibility, but it'd be possible to just export the existing tools menu configuration in v15.0 (or newer), and just replace the content in the file below accordingly.

init.ps1 文件内容

# NuGet Package installation script. Run 
# first time NuGet package installed to solution. 
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

MyProject.nuspec(部分)内容

.nuspec 文件中,确保包含 init.ps1 文件.在下面的示例中,init.ps1 的源位于Scripts"文件夹中名为MyProject"的 Visual Studio 项目中.

In the .nuspec file, ensure that the init.ps1 file is included. In the case below, the source for the init.ps1 is in a Visual Studio project named 'MyProject' in the 'Scripts' folder.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
      ...
    </metadata>
    <files>
        ...
        <!-- NuGet Package installation script. Run first time NuGet package installed to solution. -->
        <file src="Scripts\init.ps1" target="tools\init.ps1" />
    </files>
</package>

这篇关于用于自动添加 Visual Studio“外部工具..."的 PowerShell 脚本菜单选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆