Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Breaking] RuntimeIdentifier No Longer Implies SelfContained Apps by Default #30038

Merged
merged 67 commits into from
May 8, 2023

Conversation

nagilson
Copy link
Member

@nagilson nagilson commented Jan 20, 2023

RuntimeIdentifier No Longer Implies SelfContained Apps by Default

  • RIDS no longer imply Self-Contained for TFM >= 8.0

  • Warns for apps that didn't set SC but set RIDs in TFM < 8 that they need to set SC explicitly to get the same behavior with TFM 8.0. Warning will go away after SC is set, either to true or false.

  • PublishTrimmed, PublishSingleFile, and PublishAot will keep the old behavior of implying SC with 8+ TFMs, though they will only do so for publish which is a breaking change. PublishReadyToRun will not maintain this behavior and you will need to specify SelfContained explicitly to use it with PublishReadyToRun in TFMs above 7.

  • Remove the old error that occurred when -r given without -self-contained as it did not catch property in project scenarios, and it's redundant with the breaking change warning. We also have a more understandable default now, (setting one property does not add another that is not necessary.)

  • Update IL Link Tests and Publish* tests that expected the old behavior. Talked with that team, we don't want to add an implicit SelfContained there even if it will break customers as it limits the design potential in the future for these properties.

  • Talked to Blazor WASM who would be broken by this, they have created work items to add SelfContained so customers aren't broken. I modified their tests as well to pass by adding SelfContained.

This is the current VS behavior and we designed this in a NET 8 breaking changes list. It will help us align with VS behavior.

Tested Behavior:

  • RidNoLongerImpliesSelfContainedForTFM8+
  • SelfContainedPlusRuntimeIdentifierDoesNotTriggerEightTFMFDDBreakingChangeWarning

Questions:

  • Why does TargetFrameworkInference sometimes not run? I accounted for that, but don't understand the contexts.

@nagilson nagilson changed the title Make the breaking change of RID -> No Longer -> SC [Breaking] RuntimeIdentifier No Longer Implies SelfContained Apps by Default Jan 20, 2023
Update ILLink Tests to use SelfContained explicitly

Repair Publish* Tests that will be broken and now need to add SC

Update publish trimmed test to expect self contained to be explicitly specified

Update Publish* related tests to add SC

PublishSingleFile test adds SC now

IL Link and Publish* Tests now add SelfContained where a RuntimeIdentifier used to infer it automaticall per .NET 8 breaking change
Make blazor tests not give SC if already defined. Fix additional tests expecting old RID -> SC behavior

Blazor WASM Update test assets

Blazor WASM Tests Updated to add SelfContained when a RuntimeIdentifier is specified to keep old behavior after .NET 8 breaking change.

GlobalPropertyFlowTests now expect RID to not Infer SC

* Note that the failure was moved from 1 function to another ... technically the old test failed because it was relying on RID setting SC which would cause a failure as one EXE was SC but the other wasn't. With the new change, that no longer occured

Meanwhile, the other test relied on the properties flowing the RID. When the RID flowed, SC would be inferred, so the referenced project would be an EXE. But now it's not inferred, so this test should instead fail.
Remove the old self-contained warning as it would be redundant with the breaking change warning and only occurred with -r.

Co-authored-by: richlander <rlander@microsoft.com>
@nagilson nagilson marked this pull request as ready for review January 26, 2023 17:18
@nagilson nagilson requested review from AntonLapounov and a team as code owners January 26, 2023 17:18
Copy link
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ILLink test changes LGTM. We could probably clean up the tests by adding SelfContained to the project file, but no need to do so in this change.

nagilson and others added 3 commits January 26, 2023 09:29
…stake

Co-authored-by: Sven Boemer <sbomer@gmail.com>
Co-authored-by: Sven Boemer <sbomer@gmail.com>
Co-authored-by: Sven Boemer <sbomer@gmail.com>
nagilson and others added 3 commits May 2, 2023 09:10
Co-authored-by: Daniel Plaisted <dsplaisted@gmail.com>
…dentifier is Undesired


We do this as SelfContained can imply RuntimeIdentifier and before RID used to imply SelfContained, and we want this beahvior to be coupled in this  test

Co-authored-by: Daniel Plaisted <dsplaisted@gmail.com>
…k to error in older selfcontained exe reference scenarios
@nagilson nagilson enabled auto-merge May 8, 2023 16:35
@nagilson
Copy link
Member Author

nagilson commented May 8, 2023

Here's the breaking change doc: dotnet/docs#33726

@nagilson nagilson merged commit 2643cf4 into dotnet:main May 8, 2023
jonathanpeppers added a commit to dotnet/android that referenced this pull request May 16, 2023
Fixes: dotnet/sdk#32539
Changes: dotnet/installer@0ce8918...8488614
Changes: dotnet/runtime@9a7db55...888bac3
Changes: dotnet/emsdk@31a4a87...ab09b0b
Changes: dotnet/cecil@80d3f38...c32f0be

Updates:

* Microsoft.Dotnet.Sdk.Internal: from 8.0.100-preview.5.23228.7 to 8.0.100-preview.5.23264.2
* Microsoft.NETCore.App.Ref: from 8.0.0-preview.4.23225.14 to 8.0.0-preview.5.23260.3
* Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100.Transport: from 8.0.0-preview.4.23219.1 to 8.0.0-preview.5.23252.1
* Microsoft.NET.ILLink.Tasks: from 8.0.0-preview.4.23225.14 to 8.0.0-preview.5.23260.3
* Microsoft.DotNet.Cecil: from 0.11.4-alpha.23218.2 to 0.11.4-alpha.23252.1

~~ Other changes ~~

In [dotnet/sdk#30038][0], the default value for `$(SelfContained)` was
changed for various types of projects. Unforunately, this broke
`Release` builds on Android. Opting into non-self-contained builds triggers:

    error XALNS7028: System.IO.FileNotFoundException: Could not load assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'. Perhaps it doesn't exist in the Mono for Android profile?

But we can solve the issues by:

* Pass `$(SelfContained)` as `true` for all "inner builds" that run
  for each `$(RuntimeIdentifier)`.

* Set `$(UseCurrentRuntimeIdentifier)` by default, so we don't opt into
  the Host's RID. Builds would select `win-x64` or `osx-64` otherwise.

[0]: dotnet/sdk#30038

Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Jun 20, 2023
Fixes: dotnet/maui#15696
Context: dotnet/sdk#30038

In .NET 8 Preview 5, there are various changes to default values:

* `dotnet publish` is now `Release` by default

* Builds that provide a `$(RuntimeIdentifier)` are no longer "self
  contained" by default.

The result of this change is the problem:

    dotnet new android
    dotnet publish
    Microsoft.NET.RuntimeIdentifierInference.targets(212,5): error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly.

While these commands all work:

    dotnet build
    dotnet build -c Release
    dotnet publish -c Debug
    dotnet publish -r android-arm64

`Debug` configurations work fine, because trimming is not involved.
`dotnet build` works fine, because the offending default appears to be:

https://github.com/dotnet/sdk/blob/540b197311bc8d1c2a991fed1b935b094a4d7b2d/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L64-L76

`Microsoft.NET.RuntimeIdentifierInference.targets` has a lot of MSBuild
validation logic, that its main job is to emit nice error messages for
incorrect combinations of MSBuild properties/settings.

Android is kind of the odd one out when you compare to .NET console
apps, NativeAOT, etc.:

* We default to `RuntimeIdentifiers=android-arm;android-arm64;android-x86;android-x64`.

* We do our own "inner build" for each `RuntimeIdentifier`.

* Inside our build we force `$(SelfContained)` to `true` no matter what.
  As there is no such thing as a system-wide .NET on Android.

The fix appears to be to default `PublishSelfContained=false` and let
our existing logic force `SelfContained=true`.

I added a new test for this scenario. Our existing test didn't work
because it was passing a `RuntimeIdentifier`.
jonathanpeppers added a commit to dotnet/android that referenced this pull request Jun 20, 2023
Fixes: dotnet/maui#15696
Context: dotnet/sdk#30038

In .NET 8 Preview 5, there are various changes to default values:

* `dotnet publish` is now `Release` by default

* Builds that provide a `$(RuntimeIdentifier)` are no longer "self
  contained" by default.

The result of this change is the problem:

    dotnet new android
    dotnet publish
    Microsoft.NET.RuntimeIdentifierInference.targets(212,5): error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly.

While these commands all work:

    dotnet build
    dotnet build -c Release
    dotnet publish -c Debug
    dotnet publish -r android-arm64

`Debug` configurations work fine, because trimming is not involved.
`dotnet build` works fine, because the offending default appears to be:

https://github.com/dotnet/sdk/blob/540b197311bc8d1c2a991fed1b935b094a4d7b2d/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L64-L76

`Microsoft.NET.RuntimeIdentifierInference.targets` has a lot of MSBuild
validation logic, that its main job is to emit nice error messages for
incorrect combinations of MSBuild properties/settings.

Android is kind of the odd one out when you compare to .NET console
apps, NativeAOT, etc.:

* We default to `RuntimeIdentifiers=android-arm;android-arm64;android-x86;android-x64`.

* We do our own "inner build" for each `RuntimeIdentifier`.

* Inside our build we force `$(SelfContained)` to `true` no matter what.
  As there is no such thing as a system-wide .NET on Android.

The fix appears to be to default `PublishSelfContained=false` and let
our existing logic force `SelfContained=true`.

I added a new test for this scenario. Our existing test didn't catch this
because it was passing a `RuntimeIdentifier`.
@nagilson nagilson self-assigned this Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure breaking-change Using this label will notify dotnet/compat and trigger a request to file a compat bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants