Search code examples
visual-studiovisual-studio-2019csprojnetcoreapp3.1

Target V4.7.2 and netcoreapp3.1 in same project. Value does not fall witnin the expected range


I want my Framework 4.7.2 code to use a library that targets netcoreapp3.1 Nuget indicates that the library is referenced, yet I do not see it in the list of references.

I tried editing the project to change the TargetFrameworkVersion from

<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

to

<TargetFrameworkVersion>v4.7.2;netcoreapp3.1</TargetFrameworkVersion>

But saving this change causes a message

from Visual Studio

And I cannot re-load the project

I tried chainging to

<TargetFrameworkVersion>netcoreapp3.1;net472</TargetFrameworkVersion>

The build error becomes

Error       The expression "[Microsoft.Build.Utilities.ToolLocationHelper]::
GetPathToStandardLibraries(.NETFramework, netcoreapp3.1;net472, '', '', '', '')" 
cannot be evaluated. Input string was not in a correct format.              

I asked a related question to try and troubleshoot this.


Solution

  • I think your looking for <TargetFrameworks>

    so in this case:

    <TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
    

    Please note you need a SDK-style csproj. I assume this in the case for you. If not, check How to upgrade csproj files with VS2017

    See also the article about <TargetFrameworkVersion>:

    This article shows the old way to specify a target framework. SDK-style projects enable different TargetFrameworks like netstandard. For more info, see Target frameworks.