Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions src/Tasks.UnitTests/CreateCSharpManifestResourceName_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,39 @@ public void DependentUponConvention_FindsMatch()
}
}

/// <summary>
/// Opt into DependentUpon convention and load the expected file properly when the file is in a subfolder.
/// </summary>
[Fact]
public void DependentUponConvention_FindsMatchInSubfolder()
{
using (var env = TestEnvironment.Create())
{
var subfolder = env.DefaultTestDirectory.CreateDirectory("SR1");
var csFile = subfolder.CreateFile("SR1.cs", "namespace MyStuff.Namespace { class Class { } }");
var resXFile = subfolder.CreateFile("SR1.resx", "");

env.SetCurrentDirectory(env.DefaultTestDirectory.Path);

ITaskItem i = new TaskItem(@"SR1\SR1.resx");
i.SetMetadata("BuildAction", "EmbeddedResource");
// 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("MyStuff.Namespace.Class", "Expecting to find the namespace & class name from SR1.cs");
}
}

/// <summary>
/// Opt into DependentUpon convention without creating the equivalent .cs file for our resource file.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Tasks/CreateManifestResourceName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ CreateFileStream createFileStream
// If opted into convention and no DependentUpon metadata, reference "<filename>.cs" if it exists.
if (UseDependentUponConvention && string.IsNullOrEmpty(dependentUpon))
{
string conventionDependentUpon = Path.ChangeExtension(fileName, SourceFileExtension);
string conventionDependentUpon = Path.ChangeExtension(Path.GetFileName(fileName), SourceFileExtension);

if (File.Exists(conventionDependentUpon))
if (File.Exists(Path.Combine(Path.GetDirectoryName(fileName), conventionDependentUpon)))
{
dependentUpon = conventionDependentUpon;
}
Expand Down