Skip to content

Commit

Permalink
Make the breaking change of RID -> No Longer -> SC
Browse files Browse the repository at this point in the history
  • Loading branch information
nagilson committed Jan 25, 2023
1 parent 59bd83e commit 8bce0b6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -891,4 +891,8 @@ You may need to build the project on another operating system or architecture, o
<value>NETSDK1196: The SDK does not support ahead-of-time compilation. Set the PublishAot property to false.</value>
<comment>{StrBegin="NETSDK1196: "}</comment>
</data>
<data name="RuntimeIdentifierWillNoLongerImplySelfContained" xml:space="preserve">
<value>NETSDK1198: In projects with TargetFrameworks >= 8.0, RuntimeIdentifier no longer automatically gives a SelfContained app. To preserve a project's current behavior after upgrading to 8.0, consider setting SelfContained explicitly.</value>
<comment>{StrBegin="NETSDK1198: "}</comment>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<_SelfContainedWasSpecified Condition="'$(SelfContained)' != ''">true</_SelfContainedWasSpecified>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true'">
<SelfContained Condition="'$(SelfContained)' == '' and '$(RuntimeIdentifier)' != ''">true</SelfContained>
<!-- Breaking change below! Projects with 8.0+ TFMS will no longer have RuntimeIdentifier imply SelfContained. -->
<SelfContained Condition="'$(SelfContained)' == '' and '$(RuntimeIdentifier)' != '' and
'$(_TargetFrameworkVersionWithoutV)' &lt; '8.0'">true</SelfContained>
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
<_RuntimeIdentifierUsesAppHost Condition="$(RuntimeIdentifier.StartsWith('ios')) or $(RuntimeIdentifier.StartsWith('tvos')) or $(RuntimeIdentifier.StartsWith('maccatalyst')) or $(RuntimeIdentifier.StartsWith('android')) or $(RuntimeIdentifier.StartsWith('browser'))">false</_RuntimeIdentifierUsesAppHost>
<_RuntimeIdentifierUsesAppHost Condition="'$(_RuntimeIdentifierUsesAppHost)' == ''">true</_RuntimeIdentifierUsesAppHost>
Expand Down Expand Up @@ -222,10 +224,15 @@ Copyright (c) .NET Foundation. All rights reserved.
because we do not want the behavior to be a breaking change compared to version 3.0 -->

<NETSdkWarning Condition="'$(PublishReadyToRun)' == 'true' and '$(_TargetFrameworkVersionWithoutV)' &lt; '3.0'"
ResourceName="PublishReadyToRunRequiresVersion30" />
ResourceName="PublishReadyToRunRequiresVersion30" />

<NETSdkWarning Condition="'$(PublishTrimmed)' == 'true' and '$(_TargetFrameworkVersionWithoutV)' &lt; '3.0'"
ResourceName="PublishTrimmedRequiresVersion30" />
ResourceName="PublishTrimmedRequiresVersion30" />

<!-- Previously, RuntimeIdentifier (RID) implied SelfContained (SC). A breaking change in 8.0 made it so RID did not activate SC by default.
So we warn older TFM users before they upgrade to TFM 8.0 or above that they need to add <SelfContained>true</SelfContained> now to keep the same behavior.-->
<NETSdkWarning Condition="'$(RuntimeIdentifier)' != '' and '$(_TargetFrameworkVersionWithoutV)' != '' and '$(_TargetFrameworkVersionWithoutV)' &lt; '8.0' and '$(_SelfContainedWasSpecified)' != 'true' and '$(SelfContained)' == ''"
ResourceName="RuntimeIdentifierWillNoLongerImplySelfContained" />

<!-- Generate Trimming warnings for WinForms and Wpf applications-->
<NetSdkError Condition="('$(UseWindowsForms)' == 'true') and ('$(PublishTrimmed)' == 'true') and ('$(_SuppressWinFormsTrimError)' != 'true')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,81 @@ public void It_can_publish_runtime_specific_apps_with_library_dependencies_self_
publishCommand.Execute(new[] { "-property:SelfContained=true", "-property:_CommandLineDefinedSelfContained=true", $"-property:RuntimeIdentifier={rid}", "-property:_CommandLineDefinedRuntimeIdentifier=true" }).Should().Pass().And.NotHaveStdOutContaining("warning");
}

[Theory]
[InlineData("net7.0")]
[InlineData("net8.0")]
public void It_does_or_doesnt_imply_SelfContained_based_on_RuntimeIdentifier_and_TargetFramework(string targetFramework)
{
var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework);
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: targetFramework)
.WithSource()
.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
propertyGroup.Add(new XElement(ns + "RuntimeIdentifier", runtimeIdentifier));
});

var buildCommand = new BuildCommand(testAsset);
buildCommand
.Execute()
.Should()
.Pass();

var outputDirectory = buildCommand.GetOutputDirectory(targetFramework, runtimeIdentifier: runtimeIdentifier);
var selfContainedExecutable = $"HelloWorld{Constants.ExeSuffix}";
string selfContainedExecutableFullPath = Path.Combine(outputDirectory.FullName, selfContainedExecutable);

if (targetFramework == "net7.0")
{
Assert.True(File.Exists(selfContainedExecutableFullPath));
}
else
{
Assert.False(File.Exists(selfContainedExecutableFullPath)); // RuntimeIdentifier no longer implies SelfContained for TFM >= 8
}
}

[Theory]
[InlineData("net7.0", true)]
[InlineData("net7.0", false)]
[InlineData("net8.0", false)]
public void It_does_or_doesnt_warn_based_on_SelfContained_and_TargetFramework_breaking_RID_change(string targetFramework, bool defineSelfContained)
{
var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework);
var testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: targetFramework + defineSelfContained.ToString())
.WithSource()
.WithProjectChanges(project =>
{
var ns = project.Root.Name.Namespace;
var propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
propertyGroup.Add(new XElement(ns + "RuntimeIdentifier", runtimeIdentifier));
propertyGroup.Add(new XElement(ns + "SelfContained", defineSelfContained ? "true" : ""));
});

var buildCommand = new BuildCommand(testAsset);
var commandResult = buildCommand.Execute();

if (targetFramework == "net7.0" && !defineSelfContained)
{
commandResult
.Should()
.Pass()
.And
.HaveStdOutContaining(Strings.RuntimeIdentifierWillNoLongerImplySelfContained);
}
else
{
commandResult
.Should()
.Pass()
.And
.NotHaveStdOutContaining(Strings.RuntimeIdentifierWillNoLongerImplySelfContained);
}
}

[Fact]
public void It_does_not_build_SelfContained_due_to_PublishSelfContained_being_true()
{
Expand Down

0 comments on commit 8bce0b6

Please sign in to comment.