Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

package may fail to build on certain locales #2848

Open
corngood opened this issue Feb 23, 2024 · 0 comments
Open

package may fail to build on certain locales #2848

corngood opened this issue Feb 23, 2024 · 0 comments
Labels

Comments

@corngood
Copy link

corngood commented Feb 23, 2024

Describe the bug

I'm attempting a source build of the dotnet sdk, which includes this package. I'm on a arm64-darwin machine, where the current culture is en-DE.

I've reproduce

MSBuild version 17.8.3+195e7f5a3 for .NET
17.8.3.51904%

I got an error about an invalid version (say 2.21.0.1596368770542477), which includes the time because of:

<BuildNumberHours>$([MSBuild]::Divide($([System.DateTime]::Now.Subtract($([System.DateTime]::Parse($(SemanticVersionDate)))).TotalHours), 12))</BuildNumberHours>

I've reproduced this in a standalone test project simply by importing the file above and building with msbuild 17.8.3+195e7f5a3 from .net 8.0.2 sdk. The relevant code is:

    <BuildNumberHours>$([MSBuild]::Divide($([System.DateTime]::Now.Subtract($([System.DateTime]::Parse($(SemanticVersionDate)))).TotalHours), 12))</BuildNumberHours>
    <BuildNumber>$([System.Math]::Floor($(BuildNumberHours)).ToString('F0').PadLeft(5, '0'))</BuildNumber>

BuildNumberHours gets the value (e.g.) 1596,3841980177776, and BuildNumber gets the value 15963841980177776.

If I merge them into one expression like this:

<BuildNumber>$([System.Math]::Floor($([MSBuild]::Divide($([System.DateTime]::Now.Subtract($([System.DateTime]::Parse($(SemanticVersionDate)))).TotalHours), 12))).ToString('F0').PadLeft(5, '0'))</BuildNumber>

BuildNumber ends up being 01596, as expected.

I'm not sure if this is somehow.

All I can find in the docs (https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2022) is

MSBuild will try to convert string to number and number to string, and make other conversions as required.

It seems likely that msbuild is using the invariant culture for this, but not for converting property values to strings.

This also fixes it:

<BuildNumberHours>$([MSBuild]::Divide($([System.DateTime]::Now.Subtract($([System.DateTime]::Parse($(SemanticVersionDate)))).TotalHours), 12).ToString($([System.Globalization.CultureInfo]::InvariantCulture)))</BuildNumberHours>

but it doesn't work without MSBUILDENABLEALLPROPERTYFUNCTIONS=1.

@corngood corngood added the bug label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant