让 .NET Framework 项目引用 .NET Standard 程序集需要什么?
What's needed to have a .NET Framework project reference a .NET Standard assembly?
我有一个针对 .NET Framework 4.6.2 构建的项目。它的依赖项之一是针对 .NET Standard 2.0 构建的程序集。
之前在我的旧电脑上构建得很好,但现在我正在设置一个新的开发系统,当我尝试 运行 构建时,使用相同版本的同样的工具,我得到了几十个关于 Netstandard DLL 的错误,引用了一堆在 .NET Core 中流行的小型单命名空间程序集。例如:
The primary reference "Foo" could not be resolved because it has an indirect dependency on the framework assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.6.2". To resolve this problem, either remove the reference "Foo" or retarget your application to a framework version which contains "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". (MSB3268)
如果我从 GAC 明确添加对 Netstandard 2.0 的项目引用,错误将变为:
The primary reference "netstandard", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.6.2". To resolve this problem, either remove the reference "netstandard" or retarget your application to a framework version which contains "netstandard". (MSB3267)
同样,这个在旧系统上构建(并且仍然构建)没有错误,我正在尝试构建项目而不对完全相同的 IDE 和编译器进行任何更改。所以我只能假设我缺少需要在我的开发系统上安装的东西,但我不太确定它是什么。
有没有人运行以前参与过这个?我在这里发现了一些关于尝试从 C# .NET Framework 项目引用 Netstandard 程序集的其他问题,显然由于一些与 Roslyn 相关的细节,这很棘手,但我实际上在我的 NET Framework 项目中使用 Boo 语言,所以 none 这些问题特别相关,而且它以前工作得很好。
感觉应该有一个非常简单的答案,如果我知道我忽略了什么细节的话...
.NET 团队强烈建议迁移到 net472,因为 plethora of issues with the toolchain trying to retrofit .NET Standard 2.0 support onto net461–net471. If upgrading is an option for you, it will save a lot of time. .NET Framework 4.7.2 also has the side benefit of not requiring dozens of shim DLLs to be present in your bin output, and of course there are the minor enhancements that come with any .NET Framework upgrade. (Release notes: net47, net471, net472。)
https://twitter.com/terrajobst/status/1031999730320986112:
Sorry but we messed up. We tried to make .NET Framework 4.6.1 retroactively implement .NET Standard 2.0. This was a mistake as we don't have a time machine and there is a tail of bugs. If you want to consume .NET Standard 1.5+ from .NET Framework, I recommend to be on 4.7.2.
Note that that this has nothing to do with missing APIs (although .NET Framework 4.6.1 misses about 100 APIs). It's all about binding policy, assembly identities, and treatment of framework assemblies in tooling (MSBuild, ClickOnce, test runners etc).
The lesson learned here is simple: once shipped, a given version of a .NET implementation must not change the support level of .NET Standard. IOW, the supported .NET Standard number is an immutable property. Supporting a higher version requires shipping a new version.
我有一个针对 .NET Framework 4.6.2 构建的项目。它的依赖项之一是针对 .NET Standard 2.0 构建的程序集。
之前在我的旧电脑上构建得很好,但现在我正在设置一个新的开发系统,当我尝试 运行 构建时,使用相同版本的同样的工具,我得到了几十个关于 Netstandard DLL 的错误,引用了一堆在 .NET Core 中流行的小型单命名空间程序集。例如:
The primary reference "Foo" could not be resolved because it has an indirect dependency on the framework assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.6.2". To resolve this problem, either remove the reference "Foo" or retarget your application to a framework version which contains "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". (MSB3268)
如果我从 GAC 明确添加对 Netstandard 2.0 的项目引用,错误将变为:
The primary reference "netstandard", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.6.2". To resolve this problem, either remove the reference "netstandard" or retarget your application to a framework version which contains "netstandard". (MSB3267)
同样,这个在旧系统上构建(并且仍然构建)没有错误,我正在尝试构建项目而不对完全相同的 IDE 和编译器进行任何更改。所以我只能假设我缺少需要在我的开发系统上安装的东西,但我不太确定它是什么。
有没有人运行以前参与过这个?我在这里发现了一些关于尝试从 C# .NET Framework 项目引用 Netstandard 程序集的其他问题,显然由于一些与 Roslyn 相关的细节,这很棘手,但我实际上在我的 NET Framework 项目中使用 Boo 语言,所以 none 这些问题特别相关,而且它以前工作得很好。
感觉应该有一个非常简单的答案,如果我知道我忽略了什么细节的话...
.NET 团队强烈建议迁移到 net472,因为 plethora of issues with the toolchain trying to retrofit .NET Standard 2.0 support onto net461–net471. If upgrading is an option for you, it will save a lot of time. .NET Framework 4.7.2 also has the side benefit of not requiring dozens of shim DLLs to be present in your bin output, and of course there are the minor enhancements that come with any .NET Framework upgrade. (Release notes: net47, net471, net472。)
https://twitter.com/terrajobst/status/1031999730320986112:
Sorry but we messed up. We tried to make .NET Framework 4.6.1 retroactively implement .NET Standard 2.0. This was a mistake as we don't have a time machine and there is a tail of bugs. If you want to consume .NET Standard 1.5+ from .NET Framework, I recommend to be on 4.7.2.
Note that that this has nothing to do with missing APIs (although .NET Framework 4.6.1 misses about 100 APIs). It's all about binding policy, assembly identities, and treatment of framework assemblies in tooling (MSBuild, ClickOnce, test runners etc).
The lesson learned here is simple: once shipped, a given version of a .NET implementation must not change the support level of .NET Standard. IOW, the supported .NET Standard number is an immutable property. Supporting a higher version requires shipping a new version.