如何在 VSIX 安装程序中包含来自 NuGet 包的程序集? [英] How to include assemblies from NuGet packages in a VSIX Installer?
问题描述
我正在创建 Visual Studio 2017 自定义签入策略扩展.我目前的解决方案结构如下:
注意:我正在利用新的 NuGet PackageReference 方法,它这就是没有packages.config文件的原因.
<小时>我相信我已经适当地设置了我的 VSIX 清单,因为当我不引用 Microsoft.Net.Http
时一切正常(最初我是硬编码值而不是检索值).我不确定为什么包含的 Microsoft.TeamFoundationServer.ExtendedClient
NuGet 包不会引起任何问题,而 Microsoft.Net.Http
NuGet 包会引起任何问题.>
我查看了调试文件夹以查看正在编译的内容,并且我看到每个必要的程序集都被拉入,但是如果我解压 VSIX(我将其重命名为 *.zip 并解压缩),则只包含项目程序集;Nuget 引用的程序集未打包在 VSIX 包中.
我遇到了一些资源,但似乎没有任何效果:
- VSIX 包不包含引用项目的依赖项立>
- 具有项目模板和 NuGet 包的 VSIX
- 如何包含 Nuget打包在 Visual Studio 扩展 (vsix) 中
- VSIX 扩展 - 如何确保引用的 dll 或程序集包含在 VSIX 文件中?
这些问题/答案中的每一个似乎都没有解决我的具体问题.
<小时>更新:
我认为用于生成 VSIX 包的工具可能不支持 NuGet 的新 PackageReference
功能.如果我使用旧的 packages.config 功能,一切正常.我已经放入了一个 UserVoice Ticket 以支持新的 NuGet 功能.
对于像我们这样面临这个问题的穷人(nuget 使用 PackageReference 和 VSIX 依赖项),我找到了一个解决方法,灵感来自这篇文章:通过 PackageReference 引用的 NuGet 包不包括 VSIX 中的 DLL包括仅元数据版本的程序集,而不是包含代码的完整程序集).例如,这里,我手动引用了 4 个 nuget 包:
<项目组><VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'Microsoft.Win32.Registry'"/><VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.CodeDom'"/><VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.Configuration.ConfigurationManager'"/><VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.ServiceProcess.ServiceController'"/></项目组></目标>
PS:使用 Visual Studio 2017 从 15.5.4 到 15.7.3 测试
I'm working on creating a Visual Studio 2017 custom Check-In Policy extension. My current solution is structured as follows:
Note: I am taking advantage of the new NuGet PackageReference approach, which is why there is no packages.config file.
I believe I have setup my VSIX manifest appropriately since everything works perfectly when I don't reference Microsoft.Net.Http
(originally I was hard-coding in values instead of retrieving the values). I'm not sure why the Microsoft.TeamFoundationServer.ExtendedClient
NuGet package being included doesn't cause any issues, whereas the Microsoft.Net.Http
NuGet package does.
I looked at the debug folder to see what is being compiled and I see every assembly necessary being pulled in, however if I unpack the VSIX (I renamed it to *.zip and unzipped it), only the project assembly is included; the Nuget referenced assemblies are not packaged in the VSIX package.
I came across a few resources, but nothing seems to work:
- VSIX Package doesn't include referenced project's dependencies
- VSIX with Project Templates and NuGet Packages
- How to include a Nuget package in a Visual Studio Extension (vsix)
- VSIX extension - How can I ensure a referenced dll or assembly is included in the VSIX file?
Every single one of these questions/answers do not seem to address my specific problem.
Update:
I believe it is possible that the tool used to generate the VSIX package does not support the new PackageReference
feature of NuGet. If I utilize the older packages.config feature, everything works fine. I have put in a UserVoice Ticket to support the new NuGet feature.
For those poor guys like us who face this problem (nuget using PackageReference and VSIX dependencies), I found a workaround, inspired by this post: NuGet packages referenced via PackageReference don't include DLLs in VSIX that didn't fully worked for me (it was including the metadata-only version of the assembly, not the full assembly with code). For example, here, I reference 4 nuget packages manually:
<Target Name="IncludeNuGetPackageReferences" AfterTargets="GetVsixSourceItems">
<ItemGroup>
<VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'Microsoft.Win32.Registry'" />
<VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.CodeDom'" />
<VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.Configuration.ConfigurationManager'" />
<VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'System.ServiceProcess.ServiceController'" />
</ItemGroup>
</Target>
PS: Tested with Visual Studio 2017 from 15.5.4 to 15.7.3
这篇关于如何在 VSIX 安装程序中包含来自 NuGet 包的程序集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!