Skip to content

Commit def52f6

Browse files
Merge branch 'main' into merge/vs17.10-to-main
2 parents 4f6b1bb + 1e513b3 commit def52f6

File tree

5 files changed

+108
-3
lines changed

5 files changed

+108
-3
lines changed

documentation/wiki/ChangeWaves.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t
3535
- [Exec task does not trim leading whitespaces for ConsoleOutput](https://github.com/dotnet/msbuild/pull/9722)
3636
- [Introduce [MSBuild]::StableStringHash overloads](https://github.com/dotnet/msbuild/issues/9519)
3737
- [Keep the encoding of standard output & error consistent with the console code page for ToolTask](https://github.com/dotnet/msbuild/pull/9539)
38+
- [Convert.ToString during a property evaluation uses the InvariantCulture for all types](https://github.com/dotnet/msbuild/pull/9874)
3839

3940

4041
### 17.8

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
33
<Project>
44
<PropertyGroup>
5-
<VersionPrefix>17.10.0</VersionPrefix><DotNetFinalVersionKind>release</DotNetFinalVersionKind>
5+
<VersionPrefix>17.11.0</VersionPrefix>
66
<PackageValidationBaselineVersion>17.8.3</PackageValidationBaselineVersion>
77
<AssemblyVersion>15.1.0.0</AssemblyVersion>
88
<PreReleaseVersionLabel>preview</PreReleaseVersionLabel>

src/Build.UnitTests/Evaluation/Expander_Tests.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Runtime.InteropServices;
1010
using System.Runtime.Versioning;
1111
using System.Text;
12+
using System.Threading;
1213
using System.Xml;
1314
using Microsoft.Build.BackEnd;
1415
using Microsoft.Build.Collections;
@@ -4893,5 +4894,100 @@ public void ExpandItemVectorFunctions_Exists_Directories()
48934894
squiggleItems.Select(i => i.EvaluatedInclude).ShouldBe(new[] { alphaBetaPath, alphaDeltaPath }, Case.Insensitive);
48944895
}
48954896
}
4897+
4898+
[Fact]
4899+
public void ExpandItem_ConvertToStringUsingInvariantCultureForNumberData()
4900+
{
4901+
var currentThread = Thread.CurrentThread;
4902+
var originalCulture = currentThread.CurrentCulture;
4903+
var originalUICulture = currentThread.CurrentUICulture;
4904+
4905+
try
4906+
{
4907+
var svSECultureInfo = new CultureInfo("sv-SE");
4908+
using (var env = TestEnvironment.Create())
4909+
{
4910+
currentThread.CurrentCulture = svSECultureInfo;
4911+
currentThread.CurrentUICulture = svSECultureInfo;
4912+
var root = env.CreateFolder();
4913+
4914+
var projectFile = env.CreateFile(root, ".proj",
4915+
@"<Project>
4916+
4917+
<PropertyGroup>
4918+
<_value>$([MSBuild]::Subtract(0, 1))</_value>
4919+
<_otherValue Condition=""'$(_value)' &gt;= -1"">test-value</_otherValue>
4920+
</PropertyGroup>
4921+
<Target Name=""Build"" />
4922+
</Project>");
4923+
ProjectInstance projectInstance = new ProjectInstance(projectFile.Path);
4924+
projectInstance.GetPropertyValue("_value").ShouldBe("-1");
4925+
projectInstance.GetPropertyValue("_otherValue").ShouldBe("test-value");
4926+
}
4927+
}
4928+
finally
4929+
{
4930+
currentThread.CurrentCulture = originalCulture;
4931+
currentThread.CurrentUICulture = originalUICulture;
4932+
}
4933+
}
4934+
4935+
[Fact]
4936+
public void ExpandItem_ConvertToStringUsingInvariantCultureForNumberData_RespectingChangeWave()
4937+
{
4938+
// Note: Skipping the test since it is not a valid scenario when ICU mode is not used.
4939+
if (!ICUModeAvailable())
4940+
{
4941+
return;
4942+
}
4943+
4944+
var currentThread = Thread.CurrentThread;
4945+
var originalCulture = currentThread.CurrentCulture;
4946+
var originalUICulture = currentThread.CurrentUICulture;
4947+
4948+
try
4949+
{
4950+
var svSECultureInfo = new CultureInfo("sv-SE");
4951+
using (var env = TestEnvironment.Create())
4952+
{
4953+
env.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", ChangeWaves.Wave17_10.ToString());
4954+
currentThread.CurrentCulture = svSECultureInfo;
4955+
currentThread.CurrentUICulture = svSECultureInfo;
4956+
var root = env.CreateFolder();
4957+
4958+
var projectFile = env.CreateFile(root, ".proj",
4959+
@"<Project>
4960+
4961+
<PropertyGroup>
4962+
<_value>$([MSBuild]::Subtract(0, 1))</_value>
4963+
<_otherValue Condition=""'$(_value)' &gt;= -1"">test-value</_otherValue>
4964+
</PropertyGroup>
4965+
<Target Name=""Build"" />
4966+
</Project>");
4967+
var exception = Should.Throw<InvalidProjectFileException>(() =>
4968+
{
4969+
new ProjectInstance(projectFile.Path);
4970+
});
4971+
exception.BaseMessage.ShouldContain("A numeric comparison was attempted on \"$(_value)\"");
4972+
}
4973+
}
4974+
finally
4975+
{
4976+
currentThread.CurrentCulture = originalCulture;
4977+
currentThread.CurrentUICulture = originalUICulture;
4978+
}
4979+
}
4980+
4981+
/// <summary>
4982+
/// Determines if ICU mode is enabled.
4983+
/// Copied from: https://learn.microsoft.com/en-us/dotnet/core/extensions/globalization-icu#determine-if-your-app-is-using-icu
4984+
/// </summary>
4985+
private static bool ICUModeAvailable()
4986+
{
4987+
SortVersion sortVersion = CultureInfo.InvariantCulture.CompareInfo.Version;
4988+
byte[] bytes = sortVersion.SortId.ToByteArray();
4989+
int version = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
4990+
return version != 0 && version == sortVersion.FullVersion;
4991+
}
48964992
}
48974993
}

src/Build/Evaluation/Expander.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,15 @@ internal static string ConvertToString(object valueToConvert)
14781478
else
14791479
{
14801480
// The fall back is always to just convert to a string directly.
1481-
convertedString = valueToConvert.ToString();
1481+
// Issue: https://github.com/dotnet/msbuild/issues/9757
1482+
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10))
1483+
{
1484+
convertedString = Convert.ToString(valueToConvert, CultureInfo.InvariantCulture);
1485+
}
1486+
else
1487+
{
1488+
convertedString = valueToConvert.ToString();
1489+
}
14821490
}
14831491

14841492
return convertedString;

src/MSBuild/MSBuild/Microsoft.Build.CommonTypes.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ elementFormDefault="qualified">
11601160
</xs:element>
11611161
<xs:element name="Folder" type="msb:SimpleItemType" substitutionGroup="msb:Item">
11621162
<xs:annotation>
1163-
<xs:documentation><!-- _locID_text="Folder" _locComment="" -->Folder on disk</xs:documentation>
1163+
<xs:documentation><!-- _locID_text="Folder" _locComment="" -->Used by Visual Studio to identify an empty folder.</xs:documentation>
11641164
</xs:annotation>
11651165
</xs:element>
11661166
<xs:element name="Import" type="msb:SimpleItemType" substitutionGroup="msb:Item">

0 commit comments

Comments
 (0)