Skip to content
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

CopyToOutput does not support transitive references #6151

Closed
Kieranties opened this issue Nov 9, 2017 · 5 comments
Closed

CopyToOutput does not support transitive references #6151

Kieranties opened this issue Nov 9, 2017 · 5 comments

Comments

@Kieranties
Copy link

Details about Problem

Scenario

I have two packages (Alpha and Beta both target netStandard2.0) being built via dotnet pack that specify content to be copied to output:

<ItemGroup>
  <Content Include="Example\**\*" PackageCopyToOutput="true" />
</ItemGroup>

These packages build and pack correctly and contain the correct information in their nuspecs:

<contentFiles>
  <files include="any/netstandard2.0/Example/AlphaContent/alpha.txt" buildAction="Content" copyToOutput="true" />
</contentFiles>

I also have a project (netcoreapp2.0) that consumes package Alpha via nuget.

The Project references package Alpha. Package Alpha has a dependency on package Beta

So the dependency tree is:

Project
+ --- Alpha
      + --- Beta

Issue

Performing a dotnet build or dotnet publish on the Project only copies the content files for the Alpha package. It does not copy the content files for the transitive Beta package.

Info

I did find a previously raised issue for this here: https://github.com/dotnet/cli/issues/2902
However, this relates to project.json and has been closed due to no longer being supported.

Dotnet Info

> dotnet --info
.NET Command Line Tools (2.0.2)

Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.2\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Sample Project

A sample project is attached: contentFilesRepro.zip
Run .\Build.ps1 and check the contents of the artifacts directory for the created assets.

@dasMulli
Copy link

dasMulli commented Nov 9, 2017

The PrivateAssets property on package and project references defaults to contentfiles;analyzers;build so content files will be consumed, but not directly forwarded to consuming projects unless the project also adds a reference to the transitively reference package.

You can set PrivateAssets="analyzers;build" on either a PackageRefeence or ProjectReference to change this behaviour specifically for content files.

Changing the reference to the following should resolve your problem:

  <ItemGroup>
	  <ProjectReference Include="..\Beta\Beta.csproj" PrivateAssets="analyzers;build" />
  </ItemGroup>

@Kieranties
Copy link
Author

Kieranties commented Nov 9, 2017

@dasMulli A huge thanks. I'm sure I had tried various combinations of IncludeAssets and ExcludeAssets, but it seems I missed the most simple cases.

Your solution does indeed work, however I have also found that the following works:

<ItemGroup>
  <ProjectReference Include="..\Beta\Beta.csproj" IncludeAssets="contentFiles" />
</ItemGroup>

I think this more closely represents the intention to anyone viewing the code.
Many thanks for the pointer!

@candritzky
Copy link

@dasMulli Thanks, that solved the same problem for me.
The solution proposed by @Kieranties didn't work for me.

@RickStrahl
Copy link

RickStrahl commented Aug 4, 2023

The problem is that this doesn't work if the import is a NuGet package. IncludeAssets="all" has no effect to pull the runtime folders.

The only very hacky workaround is to explicitly add a reference to the exact WebView runtime needed to the parent project.

Scenario is this:

  • Create a NuGet package that has a reference to WebView
  • Create content that works on the WebView (in my case a wrapper helper library that provides interop services)
  • Import into another project via NuGet

The runtimes folder is not imported. So the native interface loader may not be present and the app fails to load the WebView. You get a blank browser (no error - no failure).

What I wanted to accomplish is to isolate my WebView usage to my library, that I then import to any project that need it. So instead of updating WV in all projects I can just use the single reference. Doesn't work though due to this issue and I still have to add the explicit WV reference along with trying to match the runtime version which is a royal pain in the ass.

@zivkan
Copy link
Member

zivkan commented Aug 4, 2023

The default value for IncludeAssets is already all, so explicitly setting it to the same value doesn't change behaviour: https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets

IncludeAssets and PrivateAssets are independent, setting one doesn't change the other. And only runtime and native asset types select files from the runtimes/ directory within the package, neither of which are included in PrivateAssets. So, whatever problem you're having seems unrelated to this issue.

I have some draft docs with an explanation about compile, runtime and native asset selection, for a docs page specifically about packaging .NET wrappers of native code. Maybe it helps: https://github.com/NuGet/docs.microsoft.com-nuget/pull/3092/files#diff-6b0651cff7e73d73334c0380db7314eeaddc84d77a1211e5cec8b7345145bc1fR29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants