dotnet / dotnet/android

.NET 6: `_ResolveAssemblies` ignores user's `AppendRuntimeIdentifierToOutputPath`

Open
#6,158 9 comments 0 reactions 2 assignees Claimed by @jonathanpeppers View on GitHub
Area: App+Library Build
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 19h
Merged PRs (30d)
252

Description

In my projects/solution I'm overriding the various `*OutputPath` MSBuild properties to move all output into a root `artifacts` directory.
```xml
$(ArtifactsBuildPath)bin/$(Configuration)/$(TargetFramework)/$(MSBuildProjectName)/
$(OutputPath)
$(ArtifactsBuildPath)obj/base/$(TargetFramework)/$(MSBuildProjectName)/
$(ArtifactsBuildPath)obj/$(Configuration)/$(TargetFramework)/$(MSBuildProjectName)/
$(IntermediateOutputPath)
false
false
```

This has been working without issues until I started testing .NET 6. On preview 6, when creating an SDK-style project as a bindings library project for an `.aar`, the following error is encountered with such a customized setup:
```
"C:\Projects\App\App.csproj" (Build target) (1:7) ->
"C:\Projects\App\App.csproj" (_ComputeFilesToPublishForRuntimeIdentifiers target) (1:8) ->
"C:\Projects\Bindings\Bindings.csproj" (default target) (4:10) ->
(CopyFilesToOutputDirectory target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4501,5): error MSB3030: Could not copy the file "C:\Projects\artifacts\build\obj\Debug\net6.0-android\android.30-arm64\Bindings\android.30-arm64\Bindings.dll" because it was not found. [C:\Projects\Bindings\Bindings.csproj]
```
As you can see the path is mentioning the runtime identifier two times, once more after the project name. This is not part of my customized setup and not desired. On the other projects in my solution (SDK-style and legacy projects for XA apps and libraries) no issue is encountered.

---

Turns out this is due to the following ignoring the property and instead always setting it to `true` here:
https://github.com/xamarin/xamarin-android/blob/c929289a7b77ecbc90c3e10aa55f9f3027ed3345/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.AssemblyResolution.targets#L65

Deleting this line resolves the issue in the affected project, while also keeping all other projects working without issues. By deleting it, the `_ResolveAssemblies` target uses the value of `AppendRuntimeIdentifierToOutputPath` that I've set - `false`.

Note: `_ResolveAssemblies` is running in the `App` project only. It's not running in `Bindings`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.