如何避免在 Visual Studio 2017 中加载 Microsoft.VisualStudio.Threading 时出错

How can I avoid an error loading Microsoft.VisualStudio.Threading in Visual Studio 2017

我已经在一个仅针对 Visual Studio 2019 的版本中记录了我的 Visual Studio 包的更新。我开始使用 NuGet 包的一个变化 Microsoft.VisualStudio.SDK,版本 16.0.202 并删除了许多对 DLL 的单独引用。

现在我已经将我的包的最新版本移植回 Visual Studio 2017 并将几个 NuGet 包(例如 Microsoft.CodeAnalysis)降级到旧版本。

我已将 Microsoft.VisualStudio.SDK 降级到版本 15.9.3,这是最旧的可用版本。

最初,这似乎在多个系统上运行良好。但是,在一个系统上,我的包没有加载,一条消息被写入 Activity 日志,类似于

Could not load file or assembly 'Microsoft.VisualStudio.Threading, Version=15.8.0.0

(该消息实际上是德语,但这是等效的英语消息。)

我可以看到两种可能的解决方案:

[1]
扔掉 Microsoft.VisualStudio.SDK 并返回引用大量单独的 DLL。

我不想那样做。

[2]
增加Visual Studio.

的最低要求版本号

使用 Microsoft.VisualStudio.SDK 版本 15.9.3,是否必须将 Visual Studio 的最低版本设置为 15.9.3?

(这会有限制,但比不加载的包要好。)

需要提高最低要求的 VS 版本。

1.For packageReference format, if one project references the Microsoft.VisualStudio.SDK package, this project actually depends on the nuget packages the Microsoft.VisualStudio.SDK depends on. We call them .

2.And for Microsoft.VisualStudio.SDK package with version 15.9.3, it also depends on Microsoft.VisualStudio.Threading package.(至少 15.8.132,默认情况下 nuget 会下载 15.8 .132)

所以你的扩展项目实际上依赖于Microsoft.VisualStudio.Threading.dll 15.8.0.0

3.And for Microsoft.VisualStudio.Threading.dll under path C:\Program Files (x86)\Microsoft Visual Studio17\xxx\Common7\IDE\PrivateAssemblies, for VS2017-15.9.16, its version is 15.8.0.0.对于 VS2017-15.0.0,其版本为 15.0.0.0。

然后如果我有一个 VS2017-15.6.x,我可以有 Microsoft.VisualStudio.Threading.dll 其版本在此范围 [15.0.0.0,15.8.0.0)。如果我们将依赖于版本 15.8.0.0 的程序集的扩展安装到比 15 更旧的 vs 版本中。8.x,我们会遇到类似的问题。

I can see two possible solutions

我认为您的用户使用旧版本可能会遇到类似情况。如果他将 vs 更新到最新的 vs2017-15.9.17,这个问题就会消失。是的,如果您使用 Microsoft.VisualStudio.SDK 版本 15.9.3,请将 Visual Studio 的最低版本设置为 15.9.3。

你可以在那里检查依赖关系:

此包还依赖于 15.9.2x,甚至 15.9.3 版本的包。为避免遇到类似Could not load file or assembly 'xxx, Version=15.9.0.0的问题,建议提高最低要求使VS版本与VS SDK版本一致。 (在VS 15.9.0版本中,我们可能不会遇到can't load xxx with 15.8.0.0的问题,但是我们可能会遇到can't load xxx with 15.9.2.0的问题)

希望对您有所帮助:)

使用VS 2022 我已经通过 install/update those nuggets

解决了这个问题

Image showing the needed nuggets