Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -202,6 +202,13 @@ private void ProcessInputFileList(
}
}

// The on-disk path of the R2R output that will be copied to the publish directory.
// For separately compiled images this matches the '--out' path passed to crossgen2 (which honors any
// subdirectory in RelativePath). For component assemblies of a composite image, crossgen2 emits them
// flat into the composite output directory using only their file names, so the publish source path must
// use just the file name while RelativePath continues to drive the final publish destination.
var outputR2RImagePublishPath = outputR2RImage;

if (eligibility.CompileSeparately)
{
// This TaskItem is the IL->R2R entry, for an input assembly that needs to be compiled into a R2R image. This will be used as
Expand All @@ -219,17 +226,19 @@ private void ProcessInputFileList(
else if (eligibility.CompileUnrootedIntoCompositeImage)
{
r2rCompositeUnrootedInput.Add(file);
outputR2RImagePublishPath = Path.Combine(OutputPath, Path.GetFileName(outputR2RImageRelativePath));
}
else if (eligibility.CompileIntoCompositeImage)
{
r2rCompositeInputList.Add(file);
outputR2RImagePublishPath = Path.Combine(OutputPath, Path.GetFileName(outputR2RImageRelativePath));
}

// This TaskItem corresponds to the output R2R image. It is equivalent to the input TaskItem, only the ItemSpec for it points to the new path
// for the newly created R2R image
TaskItem r2rFileToPublish = new(file)
{
ItemSpec = outputR2RImage
ItemSpec = outputR2RImagePublishPath
};
r2rFileToPublish.RemoveMetadata(MetadataKeys.OriginalItemSpec);
r2rFilesPublishList.Add(r2rFileToPublish);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,59 @@ void It_can_publish_readytorun_using_crossgen2_composite_mode(string targetFrame
TestProjectPublishing_Internal("Crossgen2TestApp", targetFramework, isSelfContained: true, emitNativeSymbols: false, useCrossgen2: true, composite: true, identifier: targetFramework);
}

[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
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();
}

[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData("net6.0")]
[InlineData(ToolsetInfo.CurrentTargetFramework)]
Expand Down
Loading