refit icon indicating copy to clipboard operation
refit copied to clipboard

[BUG] Unable to build Refit with MSBuild >= 17.x

Open modplug opened this issue 2 years ago • 2 comments

Describe the bug Unable to build Refit with MSBuild 17.x.

Steps To Reproduce

  1. Install MSBuild >= 17
  2. run dotnet build.
  3. See error

refit/Refit/targets/refit.targets(45,11): error MSB4086: A numeric comparison was attempted on "$([System.Version]::Parse($(_RefitMSBuildMinVersion)).CompareTo($([System.Version]::Parse($(MSBuildVersion)))))" that evaluates to "−1" instead of a number, in condition " '$([System.Version]::Parse($(_RefitMSBuildMinVersion)).CompareTo($([System.Version]::Parse($(MSBuildVersion)))))' > '0' ". [/refit/Refit.Tests/Refit.Tests.csproj]

Expected behavior I expect to be able to build the project without errors.

If I remove the following condition from the targets file it builds as expected

<Target Name="_RefitMSBuildVersionCheck" Condition=" '$([System.Version]::Parse($(_RefitMSBuildMinVersion)).CompareTo($([System.Version]::Parse($(MSBuildVersion)))))' &gt; '0' " BeforeTargets="ResolveAssemblyReferences;Build;Rebuild" > <Error Text = "Projects using Refit cannot build using MSBuild '$(MSBuildVersion)'. MSBuild '$(_RefitMSBuildMinVersion)' or later is required." /> </Target>

Environment .NET SDK (reflecting any global.json): Version: 6.0.400-preview.22330.6 Commit: da7c9ccceb

Runtime Environment: OS Name: Mac OS X OS Version: 12.4 OS Platform: Darwin RID: osx.12-arm64 Base Path: /usr/local/share/dotnet/sdk/6.0.400-preview.22330.6/

global.json file: Not found

Host: Version: 6.0.7 Architecture: arm64 Commit: 0ec02c8c96

.NET SDKs installed: 6.0.302 [/usr/local/share/dotnet/sdk] 6.0.400-preview.22330.6 [/usr/local/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

MSBuild version 17.3.0-preview-22329-01+77c72dd0f for .NET

modplug avatar Jul 25 '22 08:07 modplug

Any updates on this? I get this in Rider for Mac. Visual Studio for Mac seem to work, at least there is no error on build

dannythunder avatar Sep 12 '22 11:09 dannythunder

@modplug I created a PR: Changed the condition of _RefitMSBuildVersionCheck

Not sure if this is the way, but it seems to work.

Hopefully this PR will be accepted in some near future....

dannythunder avatar Sep 13 '22 10:09 dannythunder

I figured out what was causing the issue.

My computer was set to Norwegian locale and once I switched to English I got Refit to build again. https://github.com/dotnet/msbuild/issues/5502

modplug avatar Oct 10 '22 07:10 modplug

This is not an acceptable fix

tallichet avatar Oct 10 '22 07:10 tallichet

I agree, but the error is in MSBuild and not Refit. Refit make use of a version comparison which fails within MSBuild

modplug avatar Oct 10 '22 08:10 modplug

I had the exact same problem (MacOS, norwegian system).

You can disable internationalization in MSBuild: https://learn.microsoft.com/en-us/dotnet/core/runtime-config/globalization

DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 dotnet build

Learn about run-time settings that configure globalization aspects of a .NET Core app, for example, how it parses Japanese dates.

tormodhau avatar Nov 01 '22 08:11 tormodhau

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Apr 13 '23 00:04 github-actions[bot]