Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Fixes: #5299

When setting up Mono.Android.NET-Tests, we had to workaround an
error with duplicate @(Content) files:

error NETSDK1148: Found multiple publish output files with the same relative path: external\Java.Interop\bin\Release\java-interop.jar, \external\Java.Interop\bin\Release-netcoreapp3.1\java-interop.jar.

Android doesn't support the @(Content) build action at all, and we
emit a XA0101 warning if it is used. We even have a test for this.

However, it appears that any @(Content) from @(ProjectReference)
items are currently brought over in .NET 6, as they get added to the
@(ResolvedFileToPublish) item group by the dotnet/sdk.

Luckily there appears to be a $(_GetChildProjectCopyToPublishDirectoryItems)
MSBuild property we can set to skip this behavior:

https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L783-L794

We can set this by default, as we don't need to compute @(Content)
items in referenced projects. The library project will emit XA0101
and that is enough. I also updated a test that would have triggered
NETSDK1148 which now works.

I could also see a perf improvement in the Mono.Android.NET-Tests
project on Windows:

Before:
GetCopyToPublishDirectoryItems 21ms
After:
GetCopyToPublishDirectoryItems 0ms

Fixes: dotnet#5299

When setting up `Mono.Android.NET-Tests`, we had to workaround an
error with duplicate `@(Content)` files:

    error NETSDK1148: Found multiple publish output files with the same relative path: external\Java.Interop\bin\Release\java-interop.jar, \external\Java.Interop\bin\Release-netcoreapp3.1\java-interop.jar.

Android doesn't support the `@(Content)` build action *at all*, and we
emit a `XA0101` warning if it is used. We even have a test for this.

However, it appears that any `@(Content)` from `@(ProjectReference)`
items are currently brought over in .NET 6, as they get added to the
`@(ResolvedFileToPublish)` item group by the dotnet/sdk.

Luckily there appears to be a `$(_GetChildProjectCopyToPublishDirectoryItems)`
MSBuild property we can set to skip this behavior:

https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L783-L794

We can set this by default, as we don't need to compute `@(Content)`
items in referenced projects. The library project will emit `XA0101`
and that is enough. I also updated a test that would have triggered
`NETSDK1148` which now works.

I could also see a perf improvement in the `Mono.Android.NET-Tests`
project on Windows:

    Before:
    GetCopyToPublishDirectoryItems 21ms
    After:
    GetCopyToPublishDirectoryItems 0ms
@jonathanpeppers jonathanpeppers force-pushed the dotnet-projectreferences-content branch from 9ffb755 to 261f7ec Compare November 18, 2020 14:07
@jonathanpeppers jonathanpeppers marked this pull request as ready for review November 19, 2020 14:51
@jonpryor jonpryor merged commit 001675f into dotnet:master Nov 19, 2020
@jonathanpeppers jonathanpeppers deleted the dotnet-projectreferences-content branch November 19, 2020 18:13
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[One .NET] @(Content) usage should not be included in publish output and produce warning

3 participants