Skip to content

Commit

Permalink
Error out if SelfContained is not specified for Native AOT publish (#…
Browse files Browse the repository at this point in the history
…95496)

The SDK has logic to specify SelfContained for PublishAot automatically. Except this doesn't apply when we're using msbuild to run the `Publish` target (`_IsPublishing` is not set): https://github.com/dotnet/sdk/blob/75184c7e763197fa2971954aa5baf70ffd188799/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L64-L83

This can lead to a bad failure mode because SelfContained is the thing that ensure ILC gets all the references to assemblies it needs. It will appear to work most of the time even without SelfContained (because ILCompiler packages carries a framework with it), but it will fail for things like ASP.NET.

Enable back the logic that just errors out for this. If someone does `msbuild /t:publish` they'll get an error saying they need to also specify SelfContained instead of some weird failure mode. There was some discussion about this aspect in dotnet/sdk#28714.
  • Loading branch information
MichalStrehovsky committed Dec 6, 2023
1 parent 1890ac9 commit 1aae18a
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- The defaults currently root non-framework assemblies, which
is a no-op for portable apps. If we later support more ways
to customize the behavior we can allow linking portable apps
in some cases. If we're not running ILLink because e.g. this
is a NativeAOT app, value of SelfContained doesn't matter. -->
<NETSdkError Condition="'$(RunILLink)' != 'false' And '$(SelfContained)' != 'true'" ResourceName="ILLinkNotSupportedError" />
in some cases. -->
<NETSdkError Condition="'$(SelfContained)' != 'true'" ResourceName="ILLinkNotSupportedError" />

<Warning Condition="'$(SuppressILLinkExplicitPackageReferenceWarning)' != 'true' And
'%(PackageReference.Identity)' == 'Microsoft.NET.ILLink.Tasks' And '%(PackageReference.IsImplicitlyDefined)' != 'true'"
Expand Down

0 comments on commit 1aae18a

Please sign in to comment.