[One .NET] fix 'dotnet publish' with no arguments#8137
Merged
jonathanpeppers merged 1 commit intodotnet:mainfrom Jun 20, 2023
Merged
[One .NET] fix 'dotnet publish' with no arguments#8137jonathanpeppers merged 1 commit intodotnet:mainfrom
jonathanpeppers merged 1 commit intodotnet:mainfrom
Conversation
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`.
dellis1972
approved these changes
Jun 20, 2023
pjcollins
approved these changes
Jun 20, 2023
Member
pjcollins
left a comment
There was a problem hiding this comment.
Makes sense to me, cc @rolfbjarne in case something similar should be done on the macios side.
Member
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: |
Member
Author
|
I think we hit this, because we pass in 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: dotnet/maui#15696
Context: dotnet/sdk#30038
In .NET 8 Preview 5, there are various changes to default values:
dotnet publishis nowReleaseby defaultBuilds that provide a
$(RuntimeIdentifier)are no longer "self contained" by default.The result of this change is the problem:
While these commands all work:
Debugconfigurations work fine, because trimming is not involved.dotnet buildworks 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.targetshas 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)totrueno matter what. As there is no such thing as a system-wide .NET on Android.The fix appears to be to default
PublishSelfContained=falseand let our existing logic forceSelfContained=true.I added a new test for this scenario. Our existing test didn't catch this because it was passing a
RuntimeIdentifier.