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

Support custom culture in RAR #11000

Merged
merged 7 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t
- [Add ParameterName and PropertyName to TaskParameterEventArgs](https://github.com/dotnet/msbuild/pull/10130)
- [Emit eval props if requested by any sink](https://github.com/dotnet/msbuild/pull/10243)
- [Load Microsoft.DotNet.MSBuildSdkResolver into default load context (MSBuild.exe only)](https://github.com/dotnet/msbuild/pull/10603)
- [Support custom culture in RAR](https://github.com/dotnet/msbuild/pull/11000)
JanKrivanek marked this conversation as resolved.
Show resolved Hide resolved

### 17.10
- [AppDomain configuration is serialized without using BinFmt](https://github.com/dotnet/msbuild/pull/9320) - feature can be opted out only if [BinaryFormatter](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) is allowed at runtime by editing `MSBuild.runtimeconfig.json`. **Please note that [any usage of BinaryFormatter is insecure](https://learn.microsoft.com/dotnet/standard/serialization/binaryformatter-security-guide).**
Expand Down
20 changes: 20 additions & 0 deletions src/Framework/StringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,24 @@ internal static string GenerateRandomString(int length)
string randomBase64String = Convert.ToBase64String(randomBytes).Replace('/', '_');
return randomBase64String.Substring(0, length);
}

/// <summary>
/// Removes last occurence of <paramref name="substring"/> from <paramref name="fromString"/>, if present.
/// </summary>
/// <param name="fromString">String to be altered.</param>
/// <param name="substring">String to be removed.</param>
/// <param name="comparison">The comparison to use for finding.</param>
/// <returns>The original string (if no occurrences found) or a new string, with last instance of <paramref name="substring"/> removed.</returns>
internal static string RemoveLastInstanceOf(this string fromString, string substring, StringComparison comparison = StringComparison.Ordinal)
{
int lastOccurrenceIndex = fromString.LastIndexOf(substring, StringComparison.Ordinal);
JanKrivanek marked this conversation as resolved.
Show resolved Hide resolved

if (lastOccurrenceIndex != -1)
{
fromString = fromString.Substring(0, lastOccurrenceIndex) +
fromString.Substring(lastOccurrenceIndex + substring.Length);
}

return fromString;
}
}
3 changes: 2 additions & 1 deletion src/Tasks/AssemblyDependency/ReferenceTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,8 @@ private void FindSatellites(
// Is there a candidate satellite in that folder?
string cultureName = Path.GetFileName(subDirectory);

if (CultureInfoCache.IsValidCultureString(cultureName))
// Custom or unknown cultures can be met as well
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_14) || CultureInfoCache.IsValidCultureString(cultureName))
JanKrivanek marked this conversation as resolved.
Show resolved Hide resolved
{
string satelliteAssembly = Path.Combine(subDirectory, satelliteFilename);
if (_fileExists(satelliteAssembly))
Expand Down
10 changes: 10 additions & 0 deletions src/Tasks/AssignCulture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using Microsoft.Build.Collections;
JanKrivanek marked this conversation as resolved.
Show resolved Hide resolved
#if DEBUG
using System.Diagnostics;
#endif
Expand Down Expand Up @@ -158,6 +159,15 @@ public override bool Execute()
// https://github.com/dotnet/msbuild/issues/3064
ConversionUtilities.ValidBooleanFalse(AssignedFiles[i].GetMetadata(ItemMetadataNames.withCulture)));

// The culture was explicitly specified, but not opted in via 'RespectAlreadyAssignedItemCulture' and different will be used
if (!string.IsNullOrEmpty(existingCulture) &&
!MSBuildNameIgnoreCaseComparer.Default.Equals(existingCulture, info.culture) &&
ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_14))
JanKrivanek marked this conversation as resolved.
Show resolved Hide resolved
{
Log.LogWarningWithCodeFromResources("AssignCulture.CultureOverwritten",
existingCulture, AssignedFiles[i].ItemSpec, info.culture);
}

if (!string.IsNullOrEmpty(info.culture))
{
AssignedFiles[i].SetMetadata(ItemMetadataNames.culture, info.culture);
Expand Down
21 changes: 17 additions & 4 deletions src/Tasks/CreateCSharpManifestResourceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,25 @@ internal static string CreateManifestNameImpl(
}

dependentUponFileName = FileUtilities.FixFilePath(dependentUponFileName);
Culture.ItemCultureInfo info = Culture.GetItemCultureInfo(embeddedFileName, dependentUponFileName, treatAsCultureNeutral);
Culture.ItemCultureInfo info;

// If the item has a culture override, respect that.
if (!string.IsNullOrEmpty(culture))
if (!string.IsNullOrEmpty(culture) && ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_14))
{
info.culture = culture;
info = new Culture.ItemCultureInfo()
{
culture = culture,
cultureNeutralFilename =
embeddedFileName.RemoveLastInstanceOf("." + culture, StringComparison.OrdinalIgnoreCase)
};
}
else
{
info = Culture.GetItemCultureInfo(embeddedFileName, dependentUponFileName, treatAsCultureNeutral);
JanKrivanek marked this conversation as resolved.
Show resolved Hide resolved
// If the item has a culture override, respect that.
if (!string.IsNullOrEmpty(culture))
JanKrivanek marked this conversation as resolved.
Show resolved Hide resolved
{
info.culture = culture;
}
}

var manifestName = StringBuilderCache.Acquire();
Expand Down
7 changes: 7 additions & 0 deletions src/Tasks/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@
<data name="AssignCulture.Comment">
<value>Culture of "{0}" was assigned to file "{1}".</value>
</data>
<data name="AssignCulture.CultureOverwritten">
<value>MSB3002: Explicitly set culture "{0}" for item "{1}" was overwritten with inferred culture "{2}", because 'RespectAlreadyAssignedItemCulture' property was not set.</value>
<comment>
{StrBegin="MSB3002: "}
'RespectAlreadyAssignedItemCulture' should not be translated
</comment>
</data>
<!--
The AxImp message bucket is: MSB3656 - MSB3660.

Expand Down
8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Tasks/Resources/xlf/Strings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading