Skip to content

Commit

Permalink
Infer RID for PublishSelfContained no SelfContained as well, and fix …
Browse files Browse the repository at this point in the history
…tests regarding this.
  • Loading branch information
nagilson committed Dec 13, 2022
1 parent 17ac493 commit e3c84ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,22 @@ Copyright (c) .NET Foundation. All rights reserved.
<SelfContained>$(PublishSelfContained)</SelfContained>
</PropertyGroup>

<!-- Automatically infer the RuntimeIdentifier for properties that require it.
SelfContained without a RID is a no-op and semantically hints towards the fact that it can change the behavior of build, publish, and friends.
... So, we infer the RID for SelfContained regardless of the context.
The other publish properties are specifically labelled Publish* and don't 'NEED' their RID unless we are doing a publish, so the RID inference
... for these properties is limited to publishing only scenarios.
Finally, library projects and non-executable projects have awkward interactions here so they are excluded.-->
<PropertyGroup Condition="'$(UseCurrentRuntimeIdentifier)' == ''">
<UseCurrentRuntimeIdentifier Condition="
'$(RuntimeIdentifier)' == '' and
'$(_IsExecutable)' == 'true' and '$(IsTestProject)' != 'true' and
'$(IsRidAgnostic)' != 'true' and
('$(_IsPublishing)' == 'true' or '$(SelfContained)' == 'true') and
(
'$(SelfContained)' == 'true' or
'$(PublishReadyToRun)' == 'true' or
'$(PublishSingleFile)' == 'true' or
'$(PublishAot)' == 'true'
Expand Down Expand Up @@ -175,7 +184,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true'">

<!-- The following RID errors are asserts, and we don't expect them to ever occur. The error message is added as a safeguard.-->
<NETSdkError Condition="'$(SelfContained)' == 'true' and '$(RuntimeIdentifier)' == '' and '$(_IsPublishing)' == 'true'"
<NETSdkError Condition="'$(SelfContained)' == 'true' and '$(RuntimeIdentifier)' == '''"
ResourceName="ImplicitRuntimeIdentifierResolutionForPublishPropertyFailed"
FormatArguments="SelfContained"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,13 @@ public void It_does_not_build_SelfContained_due_to_PublishSelfContained_being_tr
[InlineData("--p:PublishReadyToRun=true")]
[InlineData("-p:PublishSingleFile=true")]
[InlineData("-p:PublishSelfContained=true")]
[InlineData("-p:SelfContained=true")]
[InlineData("-p:PublishAot=true")]
public void It_builds_without_implicit_rid_with_RuntimeIdentifier_specific_during_publish_only_properties(string property)
{
var tfm = ToolsetInfo.CurrentTargetFramework;
var testProject = new TestProject()
{
Name = "PublishImplicitRid",
IsExe = true,
TargetFrameworks = tfm,
};
testProject.RecordProperties("RuntimeIdentifier");
Expand Down
28 changes: 17 additions & 11 deletions src/Tests/dotnet-build.Tests/GivenDotnetBuildBuildsCsproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,24 +254,30 @@ public void It_does_not_warn_on_rid_with_self_contained_options_prior_to_net6()

[Theory]
[InlineData("--self-contained")]
[InlineData("-p:PublishTrimmed=true")]
[InlineData("")]
public void It_builds_with_implicit_rid_with_rid_specific_properties(string executeOptionsAndProperties)
public void It_builds_with_implicit_rid_with_SelfContained(string executeOptions)
{
var testInstance = _testAssetsManager.CopyTestAsset("HelloWorld")
.WithSource()
.WithTargetFrameworkOrFrameworks("net6.0", false)
.Restore(Log);
var targetFramework = ToolsetInfo.CurrentTargetFramework;
var testProject = new TestProject()
{
IsExe = true,
TargetFrameworks = targetFramework
};

new DotnetBuildCommand(Log)
.WithWorkingDirectory(testInstance.Path)
.Execute(executeOptionsAndProperties)
testProject.RecordProperties("RuntimeIdentifier");
var testAsset = _testAssetsManager.CreateTestProject(testProject);


new DotnetBuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name))
.Execute(executeOptions)
.Should()
.Pass()
.And
.NotHaveStdOutContaining("NETSDK1031") // Self Contained Checks
.And
.NotHaveStdErrContaining("NETSDK1190"); // Check that publish properties don't interfere with build either
.NotHaveStdErrContaining("NETSDK1190"); // Check that publish properties don't interfere with build either

var properties = testProject.GetPropertyValues(testAsset.TestRoot, targetFramework: targetFramework);
Assert.NotEqual("", properties["RuntimeIdentifier"]);
}

[RequiresMSBuildVersionFact("17.4.0.41702")]
Expand Down
31 changes: 0 additions & 31 deletions src/Tests/dotnet.Tests/dotnet-msbuild/GivenDotnetOsArchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,36 +143,5 @@ public void CommandsRunWithArchOption(string command)
.Should()
.Pass();
}

[Fact]
public void ItUsesImplicitRidWhenNoneIsSpecifiedForSelfContained()
{
CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () =>
{
var msbuildPath = "<msbuildpath>";
var currentRid = CommonOptions.GetCurrentRuntimeId();
var command = BuildCommand.FromArgs(new string[] { "--self-contained" }, msbuildPath);
command.GetArgumentsToMSBuild()
.Should()
.StartWith($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary " +
$"-property:SelfContained=True -property:_CommandLineDefinedSelfContained=true");
});
}

[Fact]
public void ItDoesNotUseImplicitRidWhenOneIsSpecifiedForSelfContained()
{
CommandDirectoryContext.PerformActionWithBasePath(WorkingDirectory, () =>
{
var msbuildPath = "<msbuildpath>";
var currentRid = CommonOptions.GetCurrentRuntimeId();
var command = BuildCommand.FromArgs(new string[] { "--self-contained", "--runtime", "fake-rid" }, msbuildPath);
command.GetArgumentsToMSBuild()
.Should()
.StartWith($"{ExpectedPrefix} -restore -consoleloggerparameters:Summary " +
$"-property:RuntimeIdentifier=fake-rid -property:_CommandLineDefinedRuntimeIdentifier=true " +
$"-property:SelfContained=True -property:_CommandLineDefinedSelfContained=true");
});
}
}
}

0 comments on commit e3c84ca

Please sign in to comment.