Alajay Varona
Alajay Varona

Reputation: 199

A numeric comparison was attempted on "$(MSBuildVersion)" that evaluates to "" instead of a number, in condition "$(MSBuildVersion) >= 16.1.0")"

I get this error when I try to reload my project that I had unloaded as shown in the screenshot below:

enter image description here

It says this line is from my Microsoft.Managed.Core.targets

Failure happens here. I believe this is the line that fails. Below is from my microsoft managed.core.targets

 <Import Project="Microsoft.Managed.EditorConfig.targets" Condition="$(MSBuildVersion) >= 16.1.0" /> 

This is from microsoft.managed.editorconfig.targets

<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright (c)  Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information. -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  <PropertyGroup>
    <!-- Default this to false until the ".editorconfig in compiler" feature is no longer experimental.
         At that point this PropertyGroup can simply be deleted. -->
    <DiscoverEditorConfigFiles Condition="'$(DiscoverEditorConfigFiles)' == ''">false</DiscoverEditorConfigFiles>
    
    
    
  </PropertyGroup>

  <ItemGroup>
    <PotentialEditorConfigFiles Include="@(Compile->GetPathsOfAllDirectoriesAbove()->Combine('.editorconfig'))" Condition="'$(DiscoverEditorConfigFiles)' != 'false'" />
    <EditorConfigFiles Include="@(PotentialEditorConfigFiles->Exists())" Condition="'$(DiscoverEditorConfigFiles)' != 'false'" />
  </ItemGroup>
  
  
</Project>

Upvotes: 18

Views: 12724

Answers (4)

Julian M&#252;ller
Julian M&#252;ller

Reputation: 89

My project file was broken, after restarting VS the project couldn't be loaded anymore. So I created a new project and copied the PropertyGroup to the broken project, then it could be loaded without errors again. In case of my WinUi 3 project it was:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>TestUI</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;ARM64</Platforms>
    <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
  </PropertyGroup>
...
</Project>

Upvotes: 3

RBT
RBT

Reputation: 25897

Microsoft (MS) Build tool on your machine is not up-to-date. The Visual Studio (VS) 2017 Integrated Development Environment (IDE) on your machine is looking for MS build tool version 16.1.0. It is evident from the version number 16.1.0 in your error message. You should update VS 2017 to latest revision to update MS build tool to latest version. When you open VS Installer EXE on your machine then you'll see an Update button in the VS 2017 section if your Visual Studio install is not up-to-date as shown in the screenshot below:

enter image description here

Click on the Update button to update VS which will internally update MS build tool as well. Start Visual Studio after the completion of update setup. Open your solution again and reload the project which is currently unloaded. It should load fine now.

Upvotes: 2

Shiroy
Shiroy

Reputation: 1818

This is the same error that I'm getting as well.

A numeric comparison was attempted on "$(MSBuildVersion)" that evaluates to "" instead of a number, in condition "$(MSBuildVersion) >= 16.1.0".

The way I resolved this was by going and checking for updates in Visual Studio and ensuring I had the latest version of visual studio.

From this site, Andy Gocke of Microsoft writes:

The Microsoft.Net.Compilers package requires newer versions of MSBuild as Visual Studio updates, so the 3.1.0 version requires MSBuild version 16.1.

Hope this helps!

Upvotes: 2

kristofvdj88
kristofvdj88

Reputation: 924

The way I was able to fix this was by simply restarting Visual Studio

Upvotes: 33

Related Questions