Visual Studio 2017 中的自定义 TFS 签入策略 [英] Custom TFS Check-In Policy in Visual Studio 2017

查看:29
本文介绍了Visual Studio 2017 中的自定义 TFS 签入策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久前,我开发了一个自定义 TFS 签入策略,它在 Visual Studio 2015 中运行良好.现在我安装了 Visual Studio 2017 并希望以与我之前使用 VS2015 相同的方式注册签入策略程序集.但这不起作用.如何在 VS2017 中注册自定义签入策略程序集?

A while ago I developed a custom TFS check-in policy that was working fine with Visual Studio 2015. Now I installed Visual Studio 2017 and wanted to register the check-in policy assembly the same way as I did with VS2015 before. But this does not work. How can I register custom check-in policy assemblies with VS2017?

对于 VS2015,我有这些注册表项:

For VS2015, I had these registry keys:

[HKEY_LOCAL_MACHINESOFTWAREWOW6432NodeMicrosoftVisualStudio14.0TeamFoundationSourceControlCheckin Policies]
"MyCheckInPolicy"="C:\Program Files\My\MyCheckInPolicy.dll"

[HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio14.0_ConfigTeamFoundationSourceControlCheckin Policies]
"MyCheckInPolicy"="C:\Program Files\My\MyCheckInPolicy.dll"

因此我为 VS2017 (15.0) 添加了这些键:

and accordingly I added those keys for VS2017 (15.0):

[HKEY_LOCAL_MACHINESOFTWAREWOW6432NodeMicrosoftVisualStudio15.0TeamFoundationSourceControlCheckin Policies]
"MyCheckInPolicy"="C:\Program Files\My\MyCheckInPolicy.dll"
[HKEY_CURRENT_USERSOFTWAREMicrosoftVisualStudio15.0_ConfigTeamFoundationSourceControlCheckin Policies]
"MyCheckInPolicy"="C:\Program Files\My\MyCheckInPolicy.dll"

但不幸的是这不起作用:

But unfortunately this does not work:

  • 如果我打开 Team Project SourceControl 设置,请转到签入策略"选项卡并尝试添加... 一个策略,MyCheckInPolicy 没有出现1
  • 如果我已经打开使用此签入策略的团队项目并执行上述操作,我会收到一条错误消息,告诉我程序集 (mycheckinpolicy)尚未注册".
  • If I open the Team Project SourceControl settings, go to the "Check-in Policy" tab and try to Add... a policy, MyCheckInPolicy does not appear1
  • If I open the team project that uses this check-in policy already and do the above, I got an error message telling me that the assembly (mycheckinpolicy) "has not been registered".

当然我在注册表更改后重新启动了 IDE,但即使 重新启动我的机器没有帮助.

Of course I restarted the IDE after the registry change, but even rebooting my machine did not help.

到目前为止我发现的信息似乎表明签入政策现在必须成为扩展(vsix)的一部分,我不想相信.

The information I found so far seems to suggest that check-in policies now have to be part of an extension (vsix), which I don't want to believe.

我猜问题出在一些引用,在将程序集加载到 IDE 中时无法解决.

I guess that the problem comes from some references that cannot be resolved when the assembly is loaded into the IDE.

MyCheckInPolicy 项目引用了 VS2015 文件夹中的 Microsoft.TeamFoundation.VersionControl.Client.dll v14.0 C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTeamFoundationTeam Explorer.
我尝试从 VS2017 文件夹中引用相应的 dll,但是该程序集在 两个 IDE 中都不起作用.

The MyCheckInPolicy project references the Microsoft.TeamFoundation.VersionControl.Client.dll v14.0 from the VS2015 folder C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDECommonExtensionsMicrosoftTeamFoundationTeam Explorer.
I tried to reference the respective dll from the VS2017 folders, but then the assembly does not work in both IDEs.

我还尝试使用 Nuget 包Microsoft.TeamFoundation.VersionControl.All"v12.0.30723.2,并将输出目录(似乎包含包的所有程序集)中的所有文件部署到中提到的位置注册表项.这产生了相同的结果:在 VS2015 和 VS2017 中都无法加载该策略.

I also tried to use the Nuget package "Microsoft.TeamFoundation.VersionControl.All" v12.0.30723.2 instead and deployed all files from the output directory (which seem to contain all assemblies of the package) to the location mentioned in the registry keys. This had the same result: the policy cannot be loaded in neither VS2015 nor VS2017.

我们使用的是 TFS 12.0.30723.0.

1所以看来 VS2017 甚至不尝试加载程序集,也不关心注册表项?

1So it seems VS2017 doesn't even try to load the assembly and does not care about the registry keys?

推荐答案

在 Visual Studio 2017 中有 重大更改 可扩展性.大部分注册表配置已移至私有"注册表:

In Visual Studio 2017 there are breaking changes to extensibility. Much of the registry configuration has been moved into a "private" registry:

为了减少对注册表的影响,Visual Studio 现在使用RegLoadAppKey 函数将注册表项存储在私有二进制文件中在 %VsAppDataFolder%privateregistry.bin 下.只有极少数的 Visual Studio 特定键保留在系统注册表中.(链接)>

To reduce the impact on the registry, Visual Studio now uses the RegLoadAppKey function to store registry keys in a private binary file under %VsAppDataFolder%privateregistry.bin. Only a very small number of Visual Studio-specific keys remain in the system registry. (link)

通过在 vsix 中将注册表项定义为 .pkgdef 文件的一部分,在安装时 VS 2017 将(我假设)将密钥写入私有注册表而不是实际注册表,这是以前版本的情况对比.这将允许选择策略.

By defining the registry keys as part of a .pkgdef file in a vsix, on installation VS 2017 will (I assume) write the keys to the private registry as opposed to the actual registry, which was the case in previous versions of VS. This will allow the policy to be picked up.

因此,以下是我在 VS 2017 中使我们的政策生效所经历的步骤:

So, here are the steps I went through to get our policies working in VS 2017:

  1. 安装 Visual Studio SDK(可以通过修改 如果您最初没有选择工作负载,请安装您的安装).
  2. 将新的 VSIX 项目添加到您的签入策略解决方案
  3. 向 VSIX 项目添加一个 .pkgdef 文件,其中包含以下内容(这是注册表项):

  1. Install the Visual Studio SDK (can be done by modifying your installation if you didn't select the workload originally).
  2. Add a new VSIX Project to your checkin policy solution
  3. Add a .pkgdef file to the VSIX project with the following (this is the registry key entry):

<代码>[$RootKey$TeamFoundationSourceControlCheckin 策略]"YourPolicy"="$PackageFolder$YourPolicy.dll"

在 VSIX 项目中修改 source.extension.vsixmanifest(使用 GUI 向导):

Modify source.extension.vsixmanifest (using the GUI wizard) in the VSIX project:

  1. 安装目标:添加最低支持的 VS 版本:
    • Microsoft.VisualStudio.Community [15.0,16.0)
    • Microsoft.VisualStudio.IntegratedShell [15.0,16.0)
  • Microsoft.VisualStudio.Assembly
    • 当前解决方案中的一个项目
    • 项目:选择您的签入政策项目
    • 文件系统上的文件
    • 路径:从第 3 步中选择您的 .pkgdef 文件.

  • 构建 VSIX 项目并分发/安装生成的 vsix
  • 这个 GitHub 存储库有助于将所有内容拼凑在一起.我在迁移到 vsix 时发现的一些怪癖:

    This GitHub repo was helpful for piecing everything together. Some quirks I found when migrating to the vsix:

    1. 默认情况下,vsix 安装现在是按用户进行的.如果您在同一台机器上的多个用户下运行 VS,则需要为每个用户安装它.vsixmanifest 中有一个选项可以为所有用户安装扩展程序,但这需要提升.
    2. 我们的签入策略使用了 app.config 文件,vsix 不支持该文件.我不得不迁移我们的设置到.settings文件.
    1. By default, vsix installations are now per-user. If you operate VS under multiple users on the same machine you will need to install it for each. There is an option in the vsixmanifest to have the extension installed for all users, but this requires elevation.
    2. Our checkin policy used an app.config file, which is not supported in a vsix. I had to migrate our settings to a .settings file.

    这篇关于Visual Studio 2017 中的自定义 TFS 签入策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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