diff --git a/src/Tasks.UnitTests/CreateCSharpManifestResourceName_Tests.cs b/src/Tasks.UnitTests/CreateCSharpManifestResourceName_Tests.cs
index ba2fded7038..47f51fe6a00 100644
--- a/src/Tasks.UnitTests/CreateCSharpManifestResourceName_Tests.cs
+++ b/src/Tasks.UnitTests/CreateCSharpManifestResourceName_Tests.cs
@@ -416,6 +416,47 @@ public void DependentUponConvention_FindsMatch()
}
}
+ ///
+ /// Opt into DependentUpon convention but don't expect it to be used for this file.
+ ///
+ [Theory]
+ [InlineData(true)]
+ [InlineData(false)]
+ public void DependentUponConvention_DoesNotApplyToNonResx(bool explicitlySpecifyType)
+ {
+ using (var env = TestEnvironment.Create())
+ {
+ var csFile = env.CreateFile("SR1.cs", "namespace MyStuff.Namespace { class Class { } }");
+ const string ResourceFileName = "SR1.txt";
+ var resourceFile = env.CreateFile(ResourceFileName, "");
+
+ // Default resource naming is based on the item include, so use a relative
+ // path here instead of a full path.
+ env.SetCurrentDirectory(Path.GetDirectoryName(resourceFile.Path));
+ ITaskItem i = new TaskItem(ResourceFileName);
+ i.SetMetadata("BuildAction", "EmbeddedResource");
+ if (explicitlySpecifyType)
+ {
+ i.SetMetadata("Type", "Non-Resx");
+ }
+ // Don't set DependentUpon so it goes by convention
+
+ CreateCSharpManifestResourceName t = new CreateCSharpManifestResourceName
+ {
+ BuildEngine = new MockEngine(_testOutput),
+ UseDependentUponConvention = true,
+ ResourceFiles = new ITaskItem[] { i }
+ };
+
+ t.Execute().ShouldBeTrue("Expected the task to succeed.");
+
+ t.ManifestResourceNames.ShouldHaveSingleItem();
+
+ t.ManifestResourceNames[0].ItemSpec.ShouldBe(ResourceFileName, "Expecting to find the namespace & class name from SR1.cs");
+ }
+ }
+
+
///
/// Opt into DependentUpon convention and load the expected file properly when the file is in a subfolder.
///
diff --git a/src/Tasks/CreateManifestResourceName.cs b/src/Tasks/CreateManifestResourceName.cs
index cc3aba62321..933b59ab40f 100644
--- a/src/Tasks/CreateManifestResourceName.cs
+++ b/src/Tasks/CreateManifestResourceName.cs
@@ -146,8 +146,20 @@ CreateFileStream createFileStream
string fileName = resourceFile.ItemSpec;
string dependentUpon = resourceFile.GetMetadata(ItemMetadataNames.dependentUpon);
- // If opted into convention and no DependentUpon metadata, reference ".cs" if it exists.
- if (UseDependentUponConvention && string.IsNullOrEmpty(dependentUpon))
+ string fileType = resourceFile.GetMetadata("Type");
+
+ // If it has "type" metadata and the value is "Resx"
+ // This value can be specified by the user, if not it will have been automatically assigned by the SplitResourcesByCulture target.
+ bool isResxFile = (!string.IsNullOrEmpty(fileType) && fileType == "Resx");
+
+ // If not, fall back onto the extension.
+ if (string.IsNullOrEmpty(fileType))
+ {
+ isResxFile = Path.GetExtension(fileName) == ".resx";
+ }
+
+ // If opted into convention and no DependentUpon metadata and is a resx file, reference ".cs" if it exists.
+ if (isResxFile && UseDependentUponConvention && string.IsNullOrEmpty(dependentUpon))
{
string conventionDependentUpon = Path.ChangeExtension(Path.GetFileName(fileName), SourceFileExtension);