Is There a Way to Force a Project Reference to .NET Standard Project to a Specific TargetFramework

Update 2020: The answer suggesting to use SetTargetFramework is a better fit, also to not conflict with other settings.

You can change your project reference like this:

  <ProjectReference Include="..\..\src\ExtendedXmlSerializer\ExtendedXmlSerializer.csproj" 
                    AdditionalProperties="TargetFramework=netstandard2.0" />

to force the selection of a specific target framework over the default "get nearest TFM" logic.


It does not work. VS 2017 15.5.5. Reference from 4.6.2 MSTest project net462 target of multitarget (net462;netstandard2.0) class library. – SerG Feb 13 at 13:34

It is true, the new way to solve that is this:

<ProjectReference Include="..\multitargeted_lib\multitargeted_lib.csproj">
  <SetTargetFramework>TargetFramework=netstandard2.0</SetTargetFramework>
</ProjectReference>

Source is here.