Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -243,10 +243,20 @@ private void ProcessInputFileList(
else if (eligibility.CompileUnrootedIntoCompositeImage)
{
r2rCompositeUnrootedInput.Add(file);

// crossgen2 emits component assemblies flat into the composite output directory using only their
// file names, so the publish source path must use just the file name. The RelativePath metadata
// (already set on r2rFileToPublish) continues to drive the final publish destination.
r2rFileToPublish.ItemSpec = Path.Combine(OutputPath, Path.GetFileName(outputR2RImageRelativePath));
}
else if (eligibility.CompileIntoCompositeImage)
{
r2rCompositeInputList.Add(file);

// crossgen2 emits component assemblies flat into the composite output directory using only their
// file names, so the publish source path must use just the file name. The RelativePath metadata
// (already set on r2rFileToPublish) continues to drive the final publish destination.
r2rFileToPublish.ItemSpec = Path.Combine(OutputPath, Path.GetFileName(outputR2RImageRelativePath));
}

r2rFileToPublish.RemoveMetadata(MetadataKeys.OriginalItemSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,60 @@ public void It_can_publish_readytorun_using_crossgen2_composite_mode(string targ
TestProjectPublishing_Internal("Crossgen2TestApp", targetFramework, isSelfContained: true, emitNativeSymbols: false, useCrossgen2: true, composite: true, identifier: targetFramework);
}

[TestMethod]
[RequiresMSBuildVersion("17.0.0.32901")]
[DataRow(ToolsetInfo.CurrentTargetFramework)]
public void It_can_publish_readytorun_composite_with_subdirectory_relative_path(string targetFramework)
{
// Regression test for https://github.com/dotnet/runtime/issues/79902
Comment thread
jtschuster marked this conversation as resolved.
Outdated
// When a target rewrites the RelativePath of the published assemblies to include a subdirectory,
// composite ReadyToRun publishing used to fail because the SDK looked for the crossgen2 component
// output under that subdirectory even though crossgen2 emits the components flat into the composite
// output directory.
var projectName = "Crossgen2SubdirApp";

var testProject = CreateTestProjectForR2RTesting(
targetFramework,
projectName,
"ClassLib");

testProject.AdditionalProperties["PublishReadyToRun"] = "True";
testProject.AdditionalProperties["PublishReadyToRunUseCrossgen2"] = "True";
testProject.AdditionalProperties["PublishReadyToRunComposite"] = "True";
testProject.SelfContained = "True";

var testProjectInstance = TestAssetsManager.CreateTestProject(testProject, identifier: targetFramework)
.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
var target = new XElement(ns + "Target",
new XAttribute("Name", "PublishAssembliesToSubdirectory"),
new XAttribute("BeforeTargets", "CreateReadyToRunImages"),
new XAttribute("AfterTargets", "ComputeResolvedFilesToPublishList"),
new XElement(ns + "ItemGroup",
new XElement(ns + "ResolvedFileToPublish",
new XAttribute("Update", "@(ResolvedFileToPublish)"),
new XAttribute("Condition", "'%(Extension)' == '.dll'"),
Comment thread
jtschuster marked this conversation as resolved.
new XAttribute("RelativePath", "subdir/%(RelativePath)"))));
project.Root.Add(target);
});

var publishCommand = new PublishCommand(testProjectInstance);
publishCommand.Execute().Should().Pass();

DirectoryInfo publishDirectory = publishCommand.GetOutputDirectory(
targetFramework,
"Debug",
testProject.RuntimeIdentifier);

var subdirectory = new DirectoryInfo(Path.Combine(publishDirectory.FullName, "subdir"));
subdirectory.Should().HaveFile($"{projectName}.dll");
subdirectory.Should().HaveFile("ClassLib.dll");

DoesImageHaveR2RInfo(Path.Combine(subdirectory.FullName, $"{projectName}.dll")).Should().BeTrue();
DoesImageHaveR2RInfo(Path.Combine(subdirectory.FullName, "ClassLib.dll")).Should().BeTrue();
}

[TestMethod]
[RequiresMSBuildVersion("17.0.0.32901")]
[DataRow("net6.0")]
Expand Down
Loading