ET标准项目的项目引用强制为特定的TargetFramework

ET标准项目的项目引用强制为特定的TargetFramework

本文介绍了有没有一种方法可以将对.NET标准项目的项目引用强制为特定的TargetFramework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是GitHub项目的贡献者,最近我们的 .NET标准遇到了一些麻烦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="..\..\src\ExtendedXmlSerializer\ExtendedXmlSerializer.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net471'">
  <ProjectReference Include="..\..\src\ExtendedXmlSerializer\ExtendedXmlSerializer.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_lib\multitargeted_lib.csproj">
  <SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework>
</ProjectReference>

来源是此处.

这篇关于有没有一种方法可以将对.NET标准项目的项目引用强制为特定的TargetFramework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 11:48