How to fix: A numeric comparison was attempted on "$(_TargetFrameworkVersionWithoutV)" that evaluates to "" instead of a number, in condition "('$(TargetFrameworkIdentifier)' != '.NETCoreApp'

This came up while trying to load a disassembled project that was then reassembled with dnSpy, but you may find it for other reasons.

If you encounter this error:

C:\Users\Me\source\repos\MyRecompiledProject.Web\MyRecompiledProject.Web.csproj : error : A numeric comparison was attempted on "$(_TargetFrameworkVersionWithoutV)" that evaluates to "" instead of a number, in condition "('$(TargetFrameworkIdentifier)' != '.NETCoreApp' OR '$(_TargetFrameworkVersionWithoutV)' < '3.0') AND ('$(TargetFrameworkIdentifier)' != '.NETStandard' OR '$(_TargetFrameworkVersionWithoutV)' < '2.1')". C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets

Or, here it is wrapped:

C:\Users\Me\source\repos\MyRecompiledProject.Web\MyRecompiledProject.Web.csproj :
error :
A numeric comparison was attempted on "$(_TargetFrameworkVersionWithoutV)"
that evaluates to "" instead of a number, in condition
"('$(TargetFrameworkIdentifier)' != '.NETCoreApp' OR
'$(_TargetFrameworkVersionWithoutV)' < '3.0') AND
('$(TargetFrameworkIdentifier)' != '.NETStandard' OR
'$(_TargetFrameworkVersionWithoutV)' < '2.1')".
C:\Program Files (x86)\Microsoft Visual Studio\2019\
Community\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets

Or here's the image:

1

I found a clue to the solution on this website in some other language:

https://edupro.id/questions/2617648/bagaimana-cara-menggunakan-msbuild-untuk-membangun-proyek-net-4-yang-sudah-ada-untuk-net-5

Here's how you fix it. Open up the .csproj file, and near the top you'll see these two lines:

<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>

Modify the first line (remove the "v"), and insert the second line, so it looks like this:

<TargetFrameworkVersion>5.0</TargetFrameworkVersion>
<_TargetFrameworkVersionWithoutV>5.0</_TargetFrameworkVersionWithoutV>
<TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier>

Load the project as you were, and it should work.

Note, one time I reloaded the project, I got an error message, but it still worked, not sure what was different, but another time I got no error message. Your mileage may vary.

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

Page top