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

Allow Cultures Within Names For EmbeddedResources #5824

Merged
3 changes: 2 additions & 1 deletion src/Tasks/AssignCulture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public override bool Execute()
Culture.ItemCultureInfo info = Culture.GetItemCultureInfo
(
AssignedFiles[i].ItemSpec,
dependentUpon
dependentUpon,
AssignedFiles[i].GetMetadata("WithCulture") == "false"
benvillalobos marked this conversation as resolved.
Show resolved Hide resolved
);

if (!string.IsNullOrEmpty(info.culture))
Expand Down
13 changes: 10 additions & 3 deletions src/Tasks/CreateCSharpManifestResourceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ Stream binaryStream
)
{
string culture = null;
bool retainCultureInResourceName = false;
if (fileName != null && itemSpecToTaskitem.TryGetValue(fileName, out ITaskItem item))
{
culture = item.GetMetadata("Culture");
// If 'WithCulture' is explicitly set to false, keep the name of the resource even if it has a culture as part of its name.
// https://github.com/dotnet/msbuild/issues/3064
retainCultureInResourceName = item.GetMetadata("WithCulture") == "false";
}

/*
Expand All @@ -59,7 +63,8 @@ The reason is that CreateManifestName can't be static because it is an
dependentUponFileName,
culture,
binaryStream,
Log
Log,
retainCultureInResourceName
);
}

Expand All @@ -78,6 +83,7 @@ The reason is that CreateManifestName can't be static because it is an
/// <param name="culture">The override culture of this resource, if any</param>
/// <param name="binaryStream">File contents binary stream, may be null</param>
/// <param name="log">Task's TaskLoggingHelper, for logging warnings or errors</param>
/// <param name="retainCultureInResourceName">Whether to treat the current file as 'culture-neutral'.</param>
/// <returns>Returns the manifest name</returns>
internal static string CreateManifestNameImpl
(
Expand All @@ -88,7 +94,8 @@ internal static string CreateManifestNameImpl
string dependentUponFileName, // May be null
string culture, // may be null
Stream binaryStream, // File contents binary stream, may be null
TaskLoggingHelper log
TaskLoggingHelper log,
bool retainCultureInResourceName = false
)
{
// Use the link file name if there is one, otherwise, fall back to file name.
Expand All @@ -99,7 +106,7 @@ TaskLoggingHelper log
}

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

// If the item has a culture override, respect that.
if (!string.IsNullOrEmpty(culture))
Expand Down
13 changes: 10 additions & 3 deletions src/Tasks/CreateVisualBasicManifestResourceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ protected override string CreateManifestName
)
{
string culture = null;
bool retainCultureInResourceName = false;
if (fileName != null && itemSpecToTaskitem.TryGetValue(fileName, out ITaskItem item))
{
culture = item.GetMetadata("Culture");
// If 'WithCulture' is explicitly set to false, keep the name of the resource even if it has a culture as part of its name.
// https://github.com/dotnet/msbuild/issues/3064
retainCultureInResourceName = item.GetMetadata("WithCulture") == "false";
}

/*
Expand All @@ -57,7 +61,8 @@ The reason is that CreateManifestName can't be static because it is an
dependentUponFileName,
culture,
binaryStream,
Log
Log,
retainCultureInResourceName
);
}

Expand All @@ -76,6 +81,7 @@ The reason is that CreateManifestName can't be static because it is an
/// <param name="culture">The override culture of this resource, if any</param>
/// <param name="binaryStream">File contents binary stream, may be null</param>
/// <param name="log">Task's TaskLoggingHelper, for logging warnings or errors</param>
/// <param name="retainCultureInResourceName">Whether to treat the current file as 'culture-neutral'.</param>
/// <returns>Returns the manifest name</returns>
internal static string CreateManifestNameImpl
(
Expand All @@ -86,7 +92,8 @@ internal static string CreateManifestNameImpl
string dependentUponFileName, // May be null
string culture,
Stream binaryStream, // File contents binary stream, may be null
TaskLoggingHelper log
TaskLoggingHelper log,
bool retainCultureInResourceName = false
)
{
// Use the link file name if there is one, otherwise, fall back to file name.
Expand All @@ -96,7 +103,7 @@ TaskLoggingHelper log
embeddedFileName = fileName;
}

Culture.ItemCultureInfo info = Culture.GetItemCultureInfo(embeddedFileName, dependentUponFileName);
Culture.ItemCultureInfo info = Culture.GetItemCultureInfo(embeddedFileName, dependentUponFileName, retainCultureInResourceName);

// If the item has a culture override, respect that.
if (!string.IsNullOrEmpty(culture))
Expand Down
9 changes: 6 additions & 3 deletions src/Tasks/Culture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ internal struct ItemCultureInfo
internal static ItemCultureInfo GetItemCultureInfo
(
string name,
string dependentUponFilename
string dependentUponFilename,
bool retainCultureInResourceName = false
)
{
ItemCultureInfo info;
Expand All @@ -38,9 +39,11 @@ string dependentUponFilename

if (String.Equals(Path.GetFileNameWithoutExtension(parentName),
Path.GetFileNameWithoutExtension(name),
StringComparison.OrdinalIgnoreCase))
StringComparison.OrdinalIgnoreCase) ||
retainCultureInResourceName)
{
// Dependent, but we treat it is as not localized because they have same base filename
// Dependent or explicitly using culture as part of the file name
benvillalobos marked this conversation as resolved.
Show resolved Hide resolved
// but we treat it is as not localized because they have same base filename
info.cultureNeutralFilename = name;
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Type>Non-Resx</Type>
</EmbeddedResource>
</ItemGroup>

benvillalobos marked this conversation as resolved.
Show resolved Hide resolved
<AssignCulture Files="@(EmbeddedResource)" Condition="'%(Extension)'!='.licx'">
<!-- Create the list of culture resx and embedded resource files -->
<Output TaskParameter="AssignedFilesWithCulture" ItemName="_MixedResourceWithCulture"/>
Expand Down