ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

package may fail to build on certain locales

Open corngood opened this issue 1 year ago • 0 comments

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:

https://github.com/microsoft/ApplicationInsights-dotnet/blob/bd8b0c25712e6f3c5275ae06b0f0e9331340fee4/.props/_GlobalStaticVersion.props#L34

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 avatar Feb 23 '24 04:02 corngood