ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.27k stars 748 forks source link

The dotnet version check fails in environments that do not have the right locale set up. #6441

Closed bstichter closed 1 year ago

bstichter commented 1 year ago

Is there an existing issue for this?

Product

Strawberry Shake

Describe the bug

The current implementation of the Strawberry Shake version check calls "dotnet --version", captures the result into a build variable, and tests the version using VersionGreaterThanOrEquals(). Any additional content output by the dotnet CLI will corrupt the version and cause this check to fail. The check either needs to use an alternate approach to retrieve the version that is not subject to this or needs to filter the output to eliminate extraneous information and retain only the version number.

The specific condition that we encountered this was because the dotnet CLI will generate warning messages if the "en_US.UTF-8" locale is not set up on your system even if it is not actually used. The warning message is: /usr/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8).

This will fail a Strawberry Shake build with the error: /opt/app-root/.nuget/packages/strawberryshake.server/13.1.0/build/StrawberryShake.Server.targets(38,20): error MSB4184: The expression "[MSBuild]::VersionGreaterThanOrEquals(/usr/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8);/usr/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8);6.0.120, 6)" cannot be evaluated. Version string was not in a correct format..

In this case, we were able to work around the problem by updating our containers to add the locale expected by the dotnet CLI. This problem would exist, however, for any additional output generated by the dotnet CLI even in other conditions.

Steps to reproduce

  1. On a system that does NOT have the "en_US.UTF-8" locale defined, do a build of a Strawberry Shake application.

Relevant log output

Microsoft (R) Build Engine version 17.0.1+b177f8fa7 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /opt/app-root/source/SolutionFolder/ProjectName.csproj (in 636 ms).
/usr/bin/sh : warning : setlocale: LC_ALL: cannot change locale (en_US.UTF-8) [/opt/app-root/source/SolutionFolder/ProjectName.csproj]
/usr/bin/sh : warning : setlocale: LC_ALL: cannot change locale (en_US.UTF-8) [/opt/app-root/source/SolutionFolder/ProjectName.csproj]
/opt/app-root/.nuget/packages/strawberryshake.server/13.1.0/build/StrawberryShake.Server.targets(38,20): error MSB4184: The expression "[MSBuild]::VersionGreaterThanOrEquals(/usr/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8);/usr/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8);6.0.120, 6)" cannot be evaluated. Version string was not in a correct format. [/opt/app-root/source/SolutionFolder/ProjectName.csproj]

Build FAILED.

/usr/bin/sh : warning : setlocale: LC_ALL: cannot change locale (en_US.UTF-8) [/opt/app-root/source/SolutionFolder/ProjectName.csproj]
/usr/bin/sh : warning : setlocale: LC_ALL: cannot change locale (en_US.UTF-8) [/opt/app-root/source/SolutionFolder/ProjectName.csproj]
/opt/app-root/.nuget/packages/strawberryshake.server/13.1.0/build/StrawberryShake.Server.targets(38,20): error MSB4184: The expression "[MSBuild]::VersionGreaterThanOrEquals(/usr/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8);/usr/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8);6.0.120, 6)" cannot be evaluated. Version string was not in a correct format. [/opt/app-root/source/SolutionFolder/ProjectName.csproj]
    2 Warning(s)
    1 Error(s)

Additional Context?

No response

Version

13.4.0

bstichter commented 1 year ago

Some commentary on the specific locale warnings mentioned in our situation can be found in this Stack article: https://stackoverflow.com/a/76283533. The change triggering this problem came from this pull request: https://github.com/ChilliCream/graphql-platform/pull/6012

sunghwan2789 commented 1 year ago

The PR https://github.com/dotnet/msbuild/pull/9391 should resolve this, but we can try ignoring stderr before the new release of msbuild

tnc1997 commented 1 year ago

but we can try ignoring stderr before the new release of msbuild

This issue might be relevant as it appears not possible to differentiate between stdout and stderr: https://github.com/dotnet/msbuild/issues/6838.

Redirecting stderr might not resolve the issue either because the errors in question are generated by preceding commands.

sunghwan2789 commented 1 year ago

The ConsoleOutput of Exec task is an array that contains each line. I think we should determine version string line and filter the output solves this?