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

[One .NET] fix 'dotnet publish' with no arguments #8137

Merged
merged 1 commit into from
Jun 20, 2023

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented 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.

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`.
Copy link
Member

@pjcollins pjcollins left a comment

Choose a reason for hiding this comment

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

Makes sense to me, cc @rolfbjarne in case something similar should be done on the macios side.

@jonathanpeppers jonathanpeppers merged commit 0cd963a into dotnet:main Jun 20, 2023
@jonathanpeppers jonathanpeppers deleted the dotnet-publish branch June 20, 2023 21:59
@rolfbjarne
Copy link
Member

Makes sense to me, cc @rolfbjarne in case something similar should be done on the macios side.

We only set SelfContained=true if we have a RuntimeIdentifier (either by default or set explicitly), so when RuntimeIdentifiers is set, we don't set SelfContained, and we don't seem to run into this problem:

https://github.com/xamarin/xamarin-macios/blob/6c32a1effcb3ea81618acaa5dc341b4428600179/dotnet/targets/Xamarin.Shared.Sdk.props#L90-L96

@jonathanpeppers
Copy link
Member Author

I think we hit this, because we pass in RuntimeIdentifier for every build. Release builds use: RuntimeIdentifiers=android-arm;android-arm64;android-x86;android-x64

Debug builds, we detect the attached device and pick the appropriate one.

grendello added a commit to grendello/xamarin-android that referenced this pull request Jun 21, 2023
* main:
  [One .NET] fix 'dotnet publish' with no arguments (dotnet#8137)
  [build] consider `$NUGET_PACKAGES` for `$(XAPackagesDir)` (dotnet#8136)
  Bump external/xamarin-android-tools from `44885bc` to `3cee10b` (dotnet#8121)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android publish: error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred
4 participants