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.
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>
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>
This seems excessive as it would seem that .netstandard2.0
should be the TargetFramework
that net471
picks up, rather than the net45
target.
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!
You can change your project reference like this:
to force the selection of a specific target framework over the default "get nearest TFM" logic.
It is true, the new way to solve that is this:
Source is here.