Skip to content

$(AndroidStripILAfterAOT)=true tries to overwrite files it shouldn't #9577

Open
@jonpryor

Description

Android framework version

net8.0-android, net9.0-android

Affected platform version

.NET 8+

Description

If you build a project with $(RunAOTCompilation)=true and $(AndroidStripILAfterAOT)=true, and .NET is installed into a non-user-writable location (e.g. /usr/local on macOS, owned by root):

dotnet new android -n net9-android-filewrite
cd net9-android-filewrite
dotnet build -bl -p:RunAOTCompilation=true -p:AndroidStripILAfterAOT=true

then the build will fail:

/usr/local/share/dotnet/packs/Microsoft.Android.Sdk.Darwin/35.0.7/targets/Microsoft.Android.Sdk.Aot.targets(142,5):
error MSB3021: Unable to copy file "obj/Debug/net9.0-android/android-x64/stripped/Microsoft.CSharp.dll" to "/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-x64/9.0.0/runtimes/android-x64/lib/net9.0/Microsoft.CSharp.dll".
Access to the path '/usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.android-x64/9.0.0/runtimes/android-x64/lib/net9.0/Microsoft.CSharp.dll' is denied.

This is concerning because it could work! I have a separate .NET 8 install in $HOME/Downloads/dotnet-sdk-8.0.206-osx-x64, and building a .NET 8 project with this .NET install with these properties set worked:

$HOME/Downloads/dotnet-sdk-8.0.206-osx-x64/dotnet build -bl -p:RunAOTCompilation=true -p:AndroidStripILAfterAOT=true

The binlog contains:

Moving file from "…/obj/Debug/net8.0-android/android-arm64/aot-in/System.Private.Xml_trimmed.dll" to "$HOME/Downloads/dotnet-sdk-8.0.206-osx-x64/packs/Microsoft.NETCore.App.Runtime.Mono.android-arm64/8.0.11/runtimes/android-arm64/lib/net8.0/System.Private.Xml.dll".

That's bananas.

But wait, it's worse! Try that with a MAUI app -- which pulls in lots of NuGet packages, with assemblies in writable $HOME/.nuget -- and:

Moving file from "…/obj/Debug/net8.0-android/android-arm/aot-in/Xamarin.AndroidX.ExifInterface_trimmed.dll" to "$HOME/.nuget/packages/xamarin.androidx.exifinterface/1.3.6.2/lib/net6.0-android31.0/Xamarin.AndroidX.ExifInterface.dll".

There goes my NuGet cache!

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions