-
Notifications
You must be signed in to change notification settings - Fork 531
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
[Xamarin.Android.Build.Tasks] don't set $(PublishSelfContained) for .NET 9 #8565
Merged
jonpryor
merged 1 commit into
dotnet:release/8.0.1xx
from
jonathanpeppers:Net8PublishSelfContained
Dec 13, 2023
Merged
[Xamarin.Android.Build.Tasks] don't set $(PublishSelfContained) for .NET 9 #8565
jonpryor
merged 1 commit into
dotnet:release/8.0.1xx
from
jonathanpeppers:Net8PublishSelfContained
Dec 13, 2023
Conversation
This file contains 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
jonathanpeppers
changed the title
[Xamarin.Android.Buid.Tasks] don't set $(PublishSelfContained) for .NET 9
[Xamarin.Android.Build.Tasks] don't set $(PublishSelfContained) for .NET 9
Dec 6, 2023
jonathanpeppers
commented
Dec 6, 2023
...id.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets
Outdated
Show resolved
Hide resolved
…ET 9 Context: dotnet/sdk@d21e6bf Context: dotnet@8fa5d99 Context: dotnet@0cd963a Building a `net8.0-android` project with a .NET 9 SDK will fail when using specific arguments: > dotnet publish -r android-arm64 MSBuild version 17.9.0-preview-23577-01+31108edc1 for .NET ... bin\Debug\dotnet\sdk\9.0.100-alpha.1.23603.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(494,5): error NETSDK1112: The runtime pack for Microsoft.Android.Runtime.34.android-arm64 was not downloaded. Try running a NuGet restore with the RuntimeIdentifier 'android-arm64'. Our repo also sets `$(DisableTransitiveFrameworkReferenceDownloads)`, which causes a slightly different error message: error NETSDK1185: The Runtime Pack for FrameworkReference 'Microsoft.Android.Runtime.34.android-arm' was not available. This may be because DisableTransitiveFrameworkReferenceDownloads was set to true. In .NET 8, 0cd963a began setting `$(PublishSelfContained)` to `false` as a way to avoid the error: Microsoft.NET.RuntimeIdentifierInference.targets(212,5): error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly. Because Android is always self-contained, we set `$(SelfContained)` through other means, and everything worked. In .NET 9, other changes were made to where this "workaround" no longer works. To fix this, Rolf introduced dotnet/sdk#d21e6bf5 and `$(AllowSelfContainedWithoutRuntimeIdentifier)` as a way to fix the issue going forward in .NET 9. We are using the new property in .NET 9 since 8fa5d99. Unfortunately, this leaves one case that is still broken: * Building with .NET 9 SDK * Building a `net8.0-android` project * `dotnet publish -r android-arm64` Which seems like for now, we could just condition our workaround for .NET 8 and below: <PublishSelfContained Condition=" '$(PublishSelfContained)' == '' and $([MSBuild]::VersionLessThan($(NETCoreSdkVersion), '9.0')) ">false</PublishSelfContained> Making this change locally, both cases work for me: * .NET 8 project, .NET 8 SDK, `dotnet publish -r android-arm64` * .NET 8 project, .NET 9 SDK, `dotnet publish -r android-arm64` The only other solution would be to create our own empty `_CheckForUnsupportedAppHostUsage` target to avoid errors, but that seems explicitly worse. We should also backport dotnet/sdk#d21e6bf5 to .NET 8 SDKs, but it will probably take a month for that to ship. After this is merged and we have a new, nightly .NET 8 build, we can restore the following unit test in main: https://github.com/xamarin/xamarin-android/blob/40cc8eaf78eb9f95abcc0e966ab274cef1692acc/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs#L202-L205
jonathanpeppers
force-pushed
the
Net8PublishSelfContained
branch
from
December 6, 2023 17:10
f5eb6e3
to
5f3f5cf
Compare
They are backporting: dotnet/sdk#37368 But this won't ship until sometime in the new year. |
Draft commit message: Context: https://github.com/dotnet/sdk/commit/d21e6bf5c5a239892d771f409841ce856bddcd89
Context: 8fa5d99341b868795b54bfa9d087bda38151a4d2
Context: 0cd963ac03fbd3d7370221adbc65b099e18f6565
Context: 95946d2e7f745ecc93efcd57cb862ae5d0912618
Context: 964746e83a85926b93057559dac70844b2ab3055
Building a `net8.0-android` project with a .NET 9 SDK will fail when
providing an RID:
> dotnet publish
# works
> dotnet publish -r android-arm64
MSBuild version 17.9.0-preview-23577-01+31108edc1 for .NET
…
bin\Debug\dotnet\sdk\9.0.100-alpha.1.23603.1\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(494,5):
error NETSDK1112: The runtime pack for Microsoft.Android.Runtime.34.android-arm64 was not downloaded. Try running a NuGet restore with the RuntimeIdentifier 'android-arm64'.
Our repo also sets `$(DisableTransitiveFrameworkReferenceDownloads)`
within unit tests (95946d2e), which causes a slightly different error
message:
error NETSDK1185: The Runtime Pack for FrameworkReference 'Microsoft.Android.Runtime.34.android-arm' was not available. This may be because DisableTransitiveFrameworkReferenceDownloads was set to true.
which matches the TODO within 8fa5d993:
> * A specific case of `dotnet publish -f net8.0-android -r android-arm`
> is failing with:
>
> error NETSDK1185: The Runtime Pack for FrameworkReference 'Microsoft.Android.Runtime.34.android-arm' was not available. This may be because DisableTransitiveFrameworkReferenceDownloads was set to true.
>
> This is related to `$(AllowSelfContainedWithoutRuntimeIdentifier)`,
> but I will address in a future PR. This will likely require .NET 8
> Android workload changes.
In .NET 8, 0cd963ac0 began setting `$(PublishSelfContained)`=false
as a way to avoid the error:
Microsoft.NET.RuntimeIdentifierInference.targets(212,5):
error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly.
Because Android is always self-contained, we set `$(SelfContained)`
through other means (964746e8; `$(SelfContained)` is set as part of the
inner builds), and everything worked.
In .NET 9, other changes were made such that this "workaround" no
longer works. To fix this, @@rolfbjarne introduced dotnet/sdk@d21e6bf5
and `$(AllowSelfContainedWithoutRuntimeIdentifier)` as a way to fix the
issue going forward in .NET 9. We are using the new property in .NET 9
since 8fa5d993.
Unfortunately, this leaves one case that is still broken:
1. Create a new project with `$(TargetFramework)`=net8.0-android
(i.e. a .NET 8 project)
2. Using the .NET 9 SDK
3. Building while specifying a RID, e.g.
dotnet publish -r android-arm64
It seems like, for now, we can just condition our workaround for
.NET 8 and below:
<PublishSelfContained Condition=" '$(PublishSelfContained)' == '' and $([MSBuild]::VersionLessThan($(NETCoreSdkVersion), '9.0')) ">false</PublishSelfContained>
Making this change locally, both cases work for me:
* .NET 8 project, .NET 8 SDK: `dotnet publish -r android-arm64`
* .NET 8 project, .NET 9 SDK: `dotnet publish -r android-arm64`
The only other solution would be to create our own empty
`_CheckForUnsupportedAppHostUsage` target to avoid errors, but that
seems explicitly worse. We should also backport dotnet/sdk#d21e6bf5
to .NET 8 SDKs, but it will probably take a month for that to ship.
After this is merged and we have a new, nightly .NET 8 build, we can
restore the [`XASdkTests.DotNetPublish()` unit test][0] on main.
[0]: https://github.com/xamarin/xamarin-android/blob/40cc8eaf78eb9f95abcc0e966ab274cef1692acc/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs#L202-L205 |
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.
Context: dotnet/sdk@d21e6bf
Context: 8fa5d99
Context: 0cd963a
Building a
net8.0-android
project with a .NET 9 SDK will fail when using specific arguments:Our repo also sets
$(DisableTransitiveFrameworkReferenceDownloads)
, which causes a slightly different error message:In .NET 8, 0cd963a began setting
$(PublishSelfContained)
tofalse
as a way to avoid the error:Because Android is always self-contained, we set
$(SelfContained)
through other means, and everything worked.In .NET 9, other changes were made to where this "workaround" no longer works. To fix this, Rolf introduced dotnet/sdk#d21e6bf5 and
$(AllowSelfContainedWithoutRuntimeIdentifier)
as a way to fix the issue going forward in .NET 9. We are using the new property in .NET 9 since 8fa5d99.Unfortunately, this leaves one case that is still broken:
Building with .NET 9 SDK
Building a
net8.0-android
projectdotnet publish -r android-arm64
Which seems like for now, we could just condition our workaround for .NET 8 and below:
Making this change locally, both cases work for me:
.NET 8 project, .NET 8 SDK,
dotnet publish -r android-arm64
.NET 8 project, .NET 9 SDK,
dotnet publish -r android-arm64
The only other solution would be to create our own empty
_CheckForUnsupportedAppHostUsage
target to avoid errors, but that seems explicitly worse. We should also backport dotnet/sdk#d21e6bf5 to .NET 8 SDKs, but it will probably take a month for that to ship.After this is merged and we have a new, nightly .NET 8 build, we can restore the following unit test in main:
https://github.com/xamarin/xamarin-android/blob/40cc8eaf78eb9f95abcc0e966ab274cef1692acc/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs#L202-L205