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

contentFiles feature is broken #6695

Closed
evil-shrike opened this issue Mar 19, 2018 · 10 comments
Closed

contentFiles feature is broken #6695

evil-shrike opened this issue Mar 19, 2018 · 10 comments

Comments

@evil-shrike
Copy link

Let's take the official sample "ContentFilesExample" from https://github.com/NuGet/Samples/tree/master/ContentFilesExample and build a package with contentFiles.
Then create a new project with dotnet new console and add the package via dotnet add package ContentFilesExample --source path/to/ContentFilesExample/authoring

Expected result:
Files from contentFiles folder are added into the project.

Actual result:
Files in contextFiles are ignored. Just a PackageReference is added and nothing more.

Documentation says that the feature contentFiles is for "NuGet 4.0+ with PackageReference". But the consuming sample in https://github.com/NuGet/Samples/tree/master/ContentFilesExample is old csproj format. So it's useless. Also please note that the documentation is terribly unclear.

ps:

D:\Work\Learn\nuget\Samples\ContentFilesExample\consuming\test>dotnet --info
.NET Command Line Tools (2.1.101)

Product Information:
 Version:            2.1.101
 Commit SHA-1 hash:  6c22303bf0

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

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.6
  Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d
@rohit21agrawal
Copy link
Contributor

@evil-shrike the content from contentFiles folder is not meant to be copied to the project directory, instead, at build time it is copied to the output directory (usually bin\$(Configuration)

@evil-shrike
Copy link
Author

Source:
Given a package - Package.1.0.0.nupkg, with contentFile in nuspec:

    <contentFiles>
      <files include="**/Reports/*.*" buildAction="Content" copyToOutput="true" />
    </contentFiles>

files inside nupkg:
\contentFiles\any\any\Reports\test.xsd

Destination:
Givien a project with installed that nuget package (as dotnet add package Package --source ..):

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Package" Version="1.0" />
  </ItemGroup>
</Project>

Now build it via dotnet build.
Go to Output bin\Debug\netcoreapp2.0 - nothing.
dst.dll
dst.pdb
dst.deps.json
dst.runtimeconfig.json
dst.runtimeconfig.dev.json

@StingyJack
Copy link
Contributor

StingyJack commented Mar 26, 2018

Content files are apparently not supported in package ref #6659

EDIT: @jainaashish - I dont want to add another comment and muddy up the chain, so I'm editing this one. You are probably correct, and I can unintentionally be quite thick at times, but expecting someone to discern a clear intent and difference between "content files" and "contentfiles" that isnt a typo may be a bit unreasonable. In the linked thread, I've been trying to elicit that difference, and more importantly the value I'd be getting with what I think is intended to be the replacement, perhaps you can explain over there (or email, w/e).

@evil-shrike
Copy link
Author

But where are they supported? For package.config only?

@jainaashish
Copy link
Contributor

@StingyJack Please read carefully before commenting, otherwise people will be confused.

Content files are supported with PackageReference via ContentFiles folder and not through Content folder. There are two different folders hierarchy in NuGet package a) Content which is only supported with packages.config and b) ContentFiles which is only supported with PackageReference.

This is clearly mentioned on NuGet docs and multiple issues. If you still find it confusing, please let us know and we'll try to make it more understandable.

@rohit21agrawal
Copy link
Contributor

@evil-shrike can you attach the nupkg which isn’t working for you?

@evil-shrike
Copy link
Author

@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Mar 26, 2018

@evil-shrike I just tried this on my machine, and the Reports folder is copied to my bin directory.

 E:\temp\contentfiletest> dotnet --version
2.1.200-preview-007474

Does a restore happen between dotnet build and dotnet add package command?

After you run the restore, could you zip the obj folder and attach it so we can see where it's going wrong?

@evil-shrike
Copy link
Author

@rohit21agrawal finally got it working. Sorry for the noise. The reason why it wasn't working is caching. I removed the package from .nuget folder in my profile, restore with -f and got the files from contentFiles folder in bin-output (once again persistent non-avoidable cache and subtle --force option hits me).

May I suggest to improve documentation on https://docs.microsoft.com/en-us/nuget/reference/nuspec#using-the-contentfiles-element-for-content-files - it says nothing about how contentFiles is processed and why it's needed.
Also the section "Including content files" is misleading as it talks about old "content" not "contentFiles" while it's referenced from "Files element":

The <package> node may contain a <files> node as a sibling to <metadata>, and a or <contentFiles> child under <metadata>, to specify which assembly and content files to include in the package. See Including assembly files and Including content files later in this topic for details.

@GF-Huang
Copy link

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