简体   繁体   English

利用不在 GAC 中的 C# 微软程序集

[英]utilizing C# microsoft assemblies that are not in the GAC

My computer only has VS2019 installed with .net versions up to 4.8.我的电脑只安装了 VS2019,安装了 .net 版本高达 4.8。 I'm attempting to use the Microsoft.Build.Construction assemblies in a program i'm working on.我正在尝试在我正在处理的程序中使用 Microsoft.Build.Construction 程序集。 When i go to add the reference->Assemblies, the only versions i have are 4.0.0.0.当我 go 添加参考-> 程序集时,我拥有的唯一版本是 4.0.0.0。 Based on my research, VS stopped adding assemblies to the GAC, so i'm forced to manually add the DLL from C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin in order to utilize the Version 15.1.0.0 that at least supports the SolutionFile calls.根据我的研究,VS 停止向 GAC 添加程序集,因此我被迫从 C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin 手动添加 DLL 以利用至少支持 SolutionFile 调用的版本 15.1.0.0。

So my question is this: should i push those versions to the GAC in order to be able to use them, or is there a better way to access non-GAC assemblies than how i did.所以我的问题是:我应该将这些版本推送到 GAC 以便能够使用它们,还是有比我做的更好的方法来访问非 GAC 程序集。

For MSBuild assemblies, you must follow the guidance of Microsoft strictly to avoid all side efforts.对于 MSBuild 程序集,您必须严格遵循 Microsoft 的指导,以避免一切附带的努力。 In general, the NuGet packages are recommended.一般来说,推荐使用 NuGet 封装。

Change MSBuild references更改 MSBuild 参考

To make sure that MSBuild loads from a central location, you must not distribute its assemblies with your application.为确保 MSBuild 从中心位置加载,您不得将其程序集与您的应用程序一起分发。

The mechanism for changing your project to avoid loading MSBuild from a central location depends on how you reference MSBuild.更改项目以避免从中心位置加载 MSBuild 的机制取决于您如何引用 MSBuild。

Use NuGet packages (preferred)使用 NuGet 封装(首选)

For detailed information, please check out the long reference有关详细信息,请查看长参考

Forget the GAC, just take the DLL in the Bin folder, copy it to your project folder in /References, and reference it from there.忘记 GAC,只需将 Bin 文件夹中的 DLL 复制到 /References 中的项目文件夹,然后从那里引用它。 This way if you use version control, the specific version of the DLL follows the source code.这样如果使用版本控制的话,DLL的具体版本遵循源码。

EDIT: As mentioned by Lex below, this is not a suitable solution for MSBuild assemblies, you should use the Nuget package instead.编辑:正如下面 Lex 所述,这不是 MSBuild 组件的合适解决方案,您应该改用 Nuget package。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM