Skip to content

Commit 36a3998

Browse files
authored
If a user expresses the intent to stifle the preview 'warning', make it happen on their behalf (#49599)
1 parent 372363c commit 36a3998

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Copyright (c) .NET Foundation. All rights reserved.
8080
<!-- Packing a tool runs the publish targets, so in that case set _IsPublishing to true -->
8181
<PropertyGroup Condition="'$(PackAsTool)' == 'true' And '$(_IsPacking)' == 'true'">
8282
<_IsPublishing>true</_IsPublishing>
83-
</PropertyGroup>
83+
</PropertyGroup>
8484

8585
<!-- Edit SelfContained to match the value of PublishSelfContained if we are publishing.
8686
This Won't affect t:/Publish (because of _IsPublishing), and also won't override a global SelfContained property.-->
@@ -175,14 +175,14 @@ Copyright (c) .NET Foundation. All rights reserved.
175175
<_SelfContainedWasSpecified Condition="'$(SelfContained)' != ''">true</_SelfContainedWasSpecified>
176176
</PropertyGroup>
177177
<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(HasRuntimeOutput)' == 'true'">
178-
178+
179179
<!-- Breaking change in .NET 8: Projects with 8.0+ TFMS will no longer have RuntimeIdentifier imply SelfContained. Note that PublishReadyToRun will imply SelfContained in these versions. -->
180180
<SelfContained Condition="'$(SelfContained)' == '' and
181181
'$(RuntimeIdentifier)' != '' and
182182
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
183183
'$(_TargetFrameworkVersionWithoutV)' != '' and
184184
$([MSBuild]::VersionLessThan($(_TargetFrameworkVersionWithoutV), '8.0'))">true</SelfContained>
185-
185+
186186
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
187187
<_RuntimeIdentifierUsesAppHost Condition="$(RuntimeIdentifier.StartsWith('ios')) or $(RuntimeIdentifier.StartsWith('tvos')) or $(RuntimeIdentifier.StartsWith('maccatalyst')) or $(RuntimeIdentifier.StartsWith('android')) or $(RuntimeIdentifier.StartsWith('browser')) or $(RuntimeIdentifier.StartsWith('wasi'))">false</_RuntimeIdentifierUsesAppHost>
188188
<_RuntimeIdentifierUsesAppHost Condition="'$(_IsPublishing)' == 'true' and '$(PublishAot)' == 'true'">false</_RuntimeIdentifierUsesAppHost>
@@ -329,6 +329,16 @@ Copyright (c) .NET Foundation. All rights reserved.
329329

330330
</Target>
331331

332+
<PropertyGroup>
333+
<!-- Suppress the .NET Core SDK preview message if the users has tried to express their intent to do so.
334+
MSBuild doesn't allow Messages to be suppressed by NoWarn, but we've trained users to reach for this,
335+
so let's bridge their intent a bit. -->
336+
<SuppressNETCoreSdkPreviewMessage
337+
Condition="'$(_NETCoreSdkIsPreview)' == 'true'
338+
AND '$(SuppressNETCoreSdkPreviewMessage)' == ''
339+
AND '$(NoWarn)' != ''
340+
AND $(NoWarn.Contains('NETSDK1057'))">true</SuppressNETCoreSdkPreviewMessage>
341+
</PropertyGroup>
332342
<Target Name="_CheckForNETCoreSdkIsPreview"
333343
BeforeTargets="_CheckForInvalidConfigurationAndPlatform"
334344
Condition=" '$(_NETCoreSdkIsPreview)' == 'true' AND '$(SuppressNETCoreSdkPreviewMessage)' != 'true' ">

test/Microsoft.NET.Build.Tests/GivenThatWeWantAMessageWhenBuildingWithAPreviewSdk.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,38 @@ public void It_displays_a_preview_message_when_using_a_preview_Sdk()
2727
.And.HaveStdOutContaining(Strings.UsingPreviewSdk);
2828
}
2929

30+
[Fact]
31+
public void It_does_not_display_preview_message_with_explicit_opt_out()
32+
{
33+
TestAsset testAsset = _testAssetsManager
34+
.CopyTestAsset("HelloWorld")
35+
.WithSource();
36+
37+
var buildCommand = new BuildCommand(testAsset);
38+
39+
buildCommand
40+
.Execute("/p:_NETCoreSdkIsPreview=true", "/p:SuppressNETCoreSdkPreviewMessage=true")
41+
.Should()
42+
.Pass()
43+
.And.NotHaveStdOutContaining(Strings.UsingPreviewSdk);
44+
}
45+
46+
[Fact]
47+
public void It_does_not_display_preview_message_with_nowarn_opt_out()
48+
{
49+
TestAsset testAsset = _testAssetsManager
50+
.CopyTestAsset("HelloWorld")
51+
.WithSource();
52+
53+
var buildCommand = new BuildCommand(testAsset);
54+
55+
buildCommand
56+
.Execute("/p:_NETCoreSdkIsPreview=true", "/p:NoWarn=NETSDK1057")
57+
.Should()
58+
.Pass()
59+
.And.NotHaveStdOutContaining(Strings.UsingPreviewSdk);
60+
}
61+
3062
[Fact]
3163
public void It_does_not_display_a_preview_message_when_using_a_release_Sdk()
3264
{

0 commit comments

Comments
 (0)