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
6 changes: 1 addition & 5 deletions src/Tasks/AssignCulture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ public override bool Execute()
AssignedFiles[i] = new TaskItem(Files[i]);

string dependentUpon = AssignedFiles[i].GetMetadata(ItemMetadataNames.dependentUpon);
Culture.ItemCultureInfo info = Culture.GetItemCultureInfo
(
AssignedFiles[i].ItemSpec,
dependentUpon
);
Culture.ItemCultureInfo info = Culture.GetItemCultureInfo(FileUtilities.FixFilePath(AssignedFiles[i].ItemSpec), dependentUpon, AssignedFiles[i]);
benvillalobos marked this conversation as resolved.
Show resolved Hide resolved

if (!string.IsNullOrEmpty(info.culture))
{
Expand Down
12 changes: 8 additions & 4 deletions src/Tasks/CreateCSharpManifestResourceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Stream binaryStream
)
{
string culture = null;
if (fileName != null && itemSpecToTaskitem.TryGetValue(fileName, out ITaskItem item))
ITaskItem item = null;
if (fileName != null && itemSpecToTaskitem.TryGetValue(fileName, out item))
benvillalobos marked this conversation as resolved.
Show resolved Hide resolved
{
culture = item.GetMetadata("Culture");
}
Expand All @@ -59,7 +60,8 @@ Stream binaryStream
dependentUponFileName,
culture,
binaryStream,
Log
Log,
item
);
}

Expand All @@ -78,6 +80,7 @@ Stream binaryStream
/// <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="item">The item itself, may be null</param>
/// <returns>Returns the manifest name</returns>
internal static string CreateManifestNameImpl
(
Expand All @@ -88,7 +91,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,
ITaskItem item = null
)
{
// Use the link file name if there is one, otherwise, fall back to file name.
Expand All @@ -99,7 +103,7 @@ TaskLoggingHelper log
}

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

// If the item has a culture override, respect that.
if (!string.IsNullOrEmpty(culture))
Expand Down
12 changes: 8 additions & 4 deletions src/Tasks/CreateVisualBasicManifestResourceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ protected override string CreateManifestName
)
{
string culture = null;
if (fileName != null && itemSpecToTaskitem.TryGetValue(fileName, out ITaskItem item))
ITaskItem item = null;
if (fileName != null && itemSpecToTaskitem.TryGetValue(fileName, out item))
benvillalobos marked this conversation as resolved.
Show resolved Hide resolved
{
culture = item.GetMetadata("Culture");
}
Expand All @@ -57,7 +58,8 @@ protected override string CreateManifestName
dependentUponFileName,
culture,
binaryStream,
Log
Log,
item
);
}

Expand All @@ -76,6 +78,7 @@ protected override string CreateManifestName
/// <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="item">The item itself, may be null</param>
/// <returns>Returns the manifest name</returns>
internal static string CreateManifestNameImpl
(
Expand All @@ -86,7 +89,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,
ITaskItem item = null
)
{
// Use the link file name if there is one, otherwise, fall back to file name.
Expand All @@ -96,7 +100,7 @@ TaskLoggingHelper log
embeddedFileName = fileName;
}

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

// If the item has a culture override, respect that.
if (!string.IsNullOrEmpty(culture))
Expand Down
10 changes: 7 additions & 3 deletions src/Tasks/Culture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Build.Framework;
using System;
using System.IO;

Expand Down Expand Up @@ -29,7 +30,8 @@ internal struct ItemCultureInfo
internal static ItemCultureInfo GetItemCultureInfo
(
string name,
string dependentUponFilename
string dependentUponFilename,
ITaskItem item = null
benvillalobos marked this conversation as resolved.
Show resolved Hide resolved
)
{
ItemCultureInfo info;
Expand All @@ -38,9 +40,11 @@ string dependentUponFilename

if (String.Equals(Path.GetFileNameWithoutExtension(parentName),
Path.GetFileNameWithoutExtension(name),
StringComparison.OrdinalIgnoreCase))
StringComparison.OrdinalIgnoreCase) ||
item?.GetMetadata("WithCulture") == "false")
{
// 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
3 changes: 2 additions & 1 deletion src/Tasks/Microsoft.Common.CurrentVersion.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2945,7 +2945,8 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<Type>Non-Resx</Type>
</EmbeddedResource>
</ItemGroup>

benvillalobos marked this conversation as resolved.
Show resolved Hide resolved

<!-- Only assign culture if 'WithCulture' isn't explcitly defined to false. See https://github.com/dotnet/msbuild/issues/3064 -->
<AssignCulture Files="@(EmbeddedResource)" Condition="'%(Extension)'!='.licx'">
<!-- Create the list of culture resx and embedded resource files -->
<Output TaskParameter="AssignedFilesWithCulture" ItemName="_MixedResourceWithCulture"/>
Expand Down