-
Notifications
You must be signed in to change notification settings - Fork 516
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
[macOS] Cannot use PublishTrimmed=true #19142
Comments
…meIdentifier. This is identical to issue dotnet#33414 (allow PublishAot=true without RuntimeIdentifier), except for the SelfContained property instead of the PublishAot property. This adds an escape hatch for a sanity check when trying to publish with SelfContained=true, but without a RuntimeIdentifier, because the check is not valid when building universal apps for macOS and Mac Catalyst (the netX-macos and netX-maccatalyst target frameworks). When building such an app, the project file will set RuntimeIdentifiers (plural): <TargetFramework>net8.0-macos</TargetFramework> <RuntimeIdentifiers>osx-x64;osx-arm</RuntimeIdentifiers> and then during the build, the macOS SDK will run two inner builds, with RuntimeIdentifiers unset, and RuntimeIdentifier set to each of the rids (and at the end merge the result into a single app). The problem is that the outer build, where RuntimeIdentifiers is set, but RuntimeIdentifier isn't, triggers the sanity check if the developer sets SelfContained=true, and that fails the build. Note that SelfContained defaults to true if PublishTrimmed=true, which means that just setting PublishTrimmed=true also triggers the sanity check. Ref: xamarin/xamarin-macios#19142
We couldn't do universal builds using NativeAOT, because .NET had a sanity check that was a bit too eager and caused unnecessary build failures. We've now been able to add an escape hatch to that sanity check, so let's use it. This makes universal builds using NativeAOT work, so we can also enable/add corresponding test variations in xharness. Also ask the runtime to allow SelfContained without a RuntimeIdentifier (the runtime has an overeager sanity check that doesn't apply to us, so we must skip it). Fixes xamarin#19142. Fixes xamarin#19142.
I can reproduce this, and a fix is in progress. Hopefully we'll be able to get it in the initial .NET 8 release. Note that
This is because we've changed the default for If you do this in your project: <PropertyGroup>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup> you should get the InvalidOperationException. |
Thanks. I always though that settings Also, does settings Tbh, I would prefer if the default |
We always set
No idea, my guess is that it could go either way, so testing it on your app is the only way to know for sure.
Note quite: we've hijacked the linker for our own purposes (in addition to what the linker usually does), and that means it's always executed (in fact we set Then you can adjust exactly what's linked by setting the
Setting Setting |
…meIdentifier. This is identical to issue #33414 (allow PublishAot=true without RuntimeIdentifier), except for the SelfContained property instead of the PublishAot property. This adds an escape hatch for a sanity check when trying to publish with SelfContained=true, but without a RuntimeIdentifier, because the check is not valid when building universal apps for macOS and Mac Catalyst (the netX-macos and netX-maccatalyst target frameworks). When building such an app, the project file will set RuntimeIdentifiers (plural): <TargetFramework>net8.0-macos</TargetFramework> <RuntimeIdentifiers>osx-x64;osx-arm</RuntimeIdentifiers> and then during the build, the macOS SDK will run two inner builds, with RuntimeIdentifiers unset, and RuntimeIdentifier set to each of the rids (and at the end merge the result into a single app). The problem is that the outer build, where RuntimeIdentifiers is set, but RuntimeIdentifier isn't, triggers the sanity check if the developer sets SelfContained=true, and that fails the build. Note that SelfContained defaults to true if PublishTrimmed=true, which means that just setting PublishTrimmed=true also triggers the sanity check. Ref: xamarin/xamarin-macios#19142
…19183) We couldn't do universal builds using NativeAOT, because .NET had a sanity check that was a bit too eager and caused unnecessary build failures. We've now been able to add an escape hatch to that sanity check, so let's use it. This makes universal builds using NativeAOT work, so we can also enable/add corresponding test variations in xharness. Also ask the runtime to allow SelfContained without a RuntimeIdentifier (the runtime has an overeager sanity check that doesn't apply to us, so we must skip it). Fixes #19142. Fixes #19142. Fixes #19206.
We couldn't do universal builds using NativeAOT, because .NET had a sanity check that was a bit too eager and caused unnecessary build failures. We've now been able to add an escape hatch to that sanity check, so let's use it. This makes universal builds using NativeAOT work, so we can also enable/add corresponding test variations in xharness. Also ask the runtime to allow SelfContained without a RuntimeIdentifier (the runtime has an overeager sanity check that doesn't apply to us, so we must skip it). Fixes xamarin#19142. Fixes xamarin#19142.
We couldn't do universal builds using NativeAOT, because .NET had a sanity check that was a bit too eager and caused unnecessary build failures. We've now been able to add an escape hatch to that sanity check, so let's use it. This makes universal builds using NativeAOT work, so we can also enable/add corresponding test variations in xharness. Also ask the runtime to allow SelfContained without a RuntimeIdentifier (the runtime has an overeager sanity check that doesn't apply to us, so we must skip it). Fixes xamarin#19142. Fixes xamarin#19142.
… using NativeAOT. (#19214) We couldn't do universal builds using NativeAOT, because .NET had a sanity check that was a bit too eager and caused unnecessary build failures. We've now been able to add an escape hatch to that sanity check, so let's use it. This makes universal builds using NativeAOT work, so we can also enable/add corresponding test variations in xharness. Also ask the runtime to allow SelfContained without a RuntimeIdentifier (the runtime has an overeager sanity check that doesn't apply to us, so we must skip it). Fixes #19142. Fixes #19142. Fixes #19206. Backport of #19183
…s when using NativeAOT. (#19213) We couldn't do universal builds using NativeAOT, because .NET had a sanity check that was a bit too eager and caused unnecessary build failures. We've now been able to add an escape hatch to that sanity check, so let's use it. This makes universal builds using NativeAOT work, so we can also enable/add corresponding test variations in xharness. Also ask the runtime to allow SelfContained without a RuntimeIdentifier (the runtime has an overeager sanity check that doesn't apply to us, so we must skip it). Fixes #19142. Fixes #19142. Fixes #19206. Backport of #19183
…meIdentifier. This is identical to issue #33414 (allow PublishAot=true without RuntimeIdentifier), except for the SelfContained property instead of the PublishAot property. This adds an escape hatch for a sanity check when trying to publish with SelfContained=true, but without a RuntimeIdentifier, because the check is not valid when building universal apps for macOS and Mac Catalyst (the netX-macos and netX-maccatalyst target frameworks). When building such an app, the project file will set RuntimeIdentifiers (plural): <TargetFramework>net8.0-macos</TargetFramework> <RuntimeIdentifiers>osx-x64;osx-arm</RuntimeIdentifiers> and then during the build, the macOS SDK will run two inner builds, with RuntimeIdentifiers unset, and RuntimeIdentifier set to each of the rids (and at the end merge the result into a single app). The problem is that the outer build, where RuntimeIdentifiers is set, but RuntimeIdentifier isn't, triggers the sanity check if the developer sets SelfContained=true, and that fails the build. Note that SelfContained defaults to true if PublishTrimmed=true, which means that just setting PublishTrimmed=true also triggers the sanity check. Ref: xamarin/xamarin-macios#19142
Steps to Reproduce
dotnet new macos
<PublishTrimmed>true</PublishTrimmed>
to test.csprojdotnet publish
Expected Behavior
App builds and gets trimmed without errors
Actual Behavior
/usr/local/share/dotnet/sdk/8.0.100-rc.1.23463.5/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(212,5): error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly. [/Users/me/GitHub/test/test.csproj]
Environment
macos 13.3.8825-net8-rc1/8.0.100-rc.1 SDK 8.0.100-rc.1
Example Project (If Possible)
test.zip
Comments
Until today, I was under the impression, that using
TrimMode=full
did trim out every unused code from my application. However, I was surprised that my app did not throw any error when using System.Json.Text in .NET8 without source generators. I expected it to throw an System.InvalidOperationException as documented (and I also saw that exception in my .NET8 Android project).As a side-note / additional question: I also added
PublishTrimmed=true
to my iOS app, built and uploaded it to TestFlight. It also does not throw the mentioned/expected System.InvalidOperationException. Does thePublishTrimmed
property even have any effect in iOS/macOS projects?The text was updated successfully, but these errors were encountered: