问题描述
我是一个 GitHub 项目的贡献者,最近我们的 .NET Standard 遇到了一些问题2.0 项目正确安装到 .NET Framework 4.5 项目.造成这种情况的原因是(如果我理解正确的话).NET Standard 2.0 最低支持 .NET Framework 4.6.1.
I am a contributor to a GitHub project, and recently we had some trouble with our .NET Standard 2.0 project installing correctly into a .NET Framework 4.5 project. The cause of this is that (if I am understanding correctly) .NET Standard 2.0 supports a minimum .NET Framework of 4.6.1.
好的,够公平的.所以我们更新了 .csproj 以创建另一个框架输出:
OK, fair enough. So we updated the .csproj to create another framework output:
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
在我们的测试项目中,支持的框架定义如下:
In our testing project, the supported frameworks are defined as such:
<TargetFrameworks>netcoreapp2.0;net471;net45</TargetFrameworks>
然而,我们遇到了 net471
构建的问题,因为它似乎选择了 net45
框架而不是 netstandard2.0
代码>.为了让它工作,我们必须设置类库的 TargetFrameworks
如下:
However, we are running into a problem with the net471
build as it seems to be picking up the net45
framework and not the netstandard2.0
. In order to get this working, we are having to set the TargetFrameworks
of the class library as such:
<TargetFrameworks>netstandard2.0;net471;net45</TargetFrameworks>
这似乎有些过分了,因为看起来 .netstandard2.0
应该是 net471
选择的 TargetFramework
,而不是 >net45
目标.
This seems excessive as it would seem that .netstandard2.0
should be the TargetFramework
that net471
picks up, rather than the net45
target.
有没有办法强制项目引用特定的TargetFramework
?我确实在我们的测试项目中尝试了以下方法,但似乎没有用:
Is there a way to force a project reference to a particular TargetFramework
? I did try the following in our testing project, but it did not seem work:
<ItemGroup Condition="'$(TargetFramework)' != 'net471'">
<ProjectReference Include="....srcExtendedXmlSerializerExtendedXmlSerializer.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net471'">
<ProjectReference Include="....srcExtendedXmlSerializerExtendedXmlSerializer.csproj">
<TargetFramework>netstandard2.0</TargetFramework>
</ProjectReference>
</ItemGroup>
预先感谢您提供的任何帮助!
Thank you in advance for any assistance you can provide!
推荐答案
没错,解决这个问题的新方法是这样的:
It is true, the new way to solve that is this:
<ProjectReference Include="..multitargeted_libmultitargeted_lib.csproj">
<SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework>
</ProjectReference>
来源是这里.
这篇关于有没有办法将 .NET Standard 项目的项目引用强制到特定的 TargetFramework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!