Skip to content

[GenerateEmbeddedResourcesManifest] handle Items with empty LogicalName #29306 #47887

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

Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand Down Expand Up @@ -90,11 +90,11 @@ public Manifest BuildManifest(EmbeddedItem[] processedItems)
return manifest;
}

private static string GetManifestPath(ITaskItem taskItem) => string.Equals(taskItem.GetMetadata(LogicalName), taskItem.GetMetadata(ManifestResourceName)) ?
private static string GetManifestPath(ITaskItem taskItem) => string.IsNullOrEmpty(taskItem.GetMetadata(LogicalName)) || string.Equals(taskItem.GetMetadata(LogicalName), taskItem.GetMetadata(ManifestResourceName)) ?
taskItem.GetMetadata(TargetPath) :
NormalizePath(taskItem.GetMetadata(LogicalName));

private static string GetAssemblyResourceName(ITaskItem taskItem) => string.Equals(taskItem.GetMetadata(LogicalName), taskItem.GetMetadata(ManifestResourceName)) ?
private static string GetAssemblyResourceName(ITaskItem taskItem) => string.IsNullOrEmpty(taskItem.GetMetadata(LogicalName)) || string.Equals(taskItem.GetMetadata(LogicalName), taskItem.GetMetadata(ManifestResourceName)) ?
taskItem.GetMetadata(ManifestResourceName) :
taskItem.GetMetadata(LogicalName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ public void CreateEmbeddedItems_MapsMetadataFromEmbeddedResources_WithLogicalNam
Assert.Equal(expectedItems, embeddedItems);
}

[Fact]
public void CreateEmbeddedItems_MapsMetadataFromEmbeddedResources_WithEmptyLogicalName()
{
// Arrange
var task = new TestGenerateEmbeddedResourcesManifest();
var embeddedFiles = CreateEmbeddedResource(
CreateMetadata("site.css"),
CreateMetadata(@"lib\js\jquery.validate.js", logicalName: string.Empty));

var expectedItems = new[]
{
CreateEmbeddedItem("site.css","site.css"),
CreateEmbeddedItem(@"lib\js\jquery.validate.js","lib.js.jquery.validate.js")
};

// Act
var embeddedItems = task.CreateEmbeddedItems(embeddedFiles);

// Assert
Assert.Equal(expectedItems, embeddedItems);
}

[Fact]
public void BuildManifest_CanCreatesManifest_ForTopLevelFiles()
{
Expand Down