NuGet 3.3+: contentFiles not added to project

After reading all that I can find about the new NuGet 3.3+ contentFiles element, I still can't get it to work in my package. I have a package that targets both net46 and uap10.0 , and choosing the right DLLs for the project type and platform works as expected. But I would also like to add two files to the project for installing the package, one CSV file for all projects and platforms and one code file for C # or VB.Net (with buildAction="Compile" ). Here's a shortened version of my latest .nuspec file:

 <?xml version="1.0" encoding="utf-8" ?> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <metadata minClientVersion="3.3.0"> ... <contentFiles> <files include="any\any\ErrorCodes.csv" buildAction="None" copyToOutput="false" /> <files include="cs\any\Errors.cs.pp" buildAction="Compile" /> <files include="vb\any\Errors.vb" buildAction="Compile" /> </contentFiles> </metadata> <files> <file src="contentFiles\any\any\ErrorCodes.csv" target="contentFiles\any\any\" /> <file src="contentFiles\cs\any\Errors.cs.pp" target="contentFiles\cs\any\" /> <file src="contentFiles\vb\any\Errors.vb" target="contentFiles\vb\any\" /> ... </files> </package> 

The package is created without errors, and it contains three files in the contentFiles folder with the specified directory structure.

But when I install the package - I tried it with both a universal application (C # and VB) and the .NET 4.6 console application, which I modified to use the project.json file - a link to the DLL was added, but the content files weren’t They are added to the project structure and are not copied to the project directory.

I am grateful for any contribution!

+5
source share
1 answer

OK, I found that contentFiles actually work, but not in the way I expected. A brief description for everyone who could not find their content files:

  • NuGet 3.3+ contentFiles are not added to the project structure. You will not see them in Visual Studio.
  • Instead, the files are extracted to a folder in the obj project folder and referenced (if the file is code). You will even see classes or methods in your ContentFiles available in IntelliSense. In my case, the Errors class was available, although it was not visible anywhere in the project.
  • The path of the extracted files has the following scheme: \ obj \ <Debug or Release> \ NuGet \ <GUID name> \ <NuGet> \ <version> \

I'm not sure if I like this new mechanism. Code coming from some invisible source that I don’t see in Visual Studio (the library sent through NuGet is visible in the links, any code that it passes through contentFiles cannot) can sometimes cause problems. I really found that the contentFiles mechanism worked when I received the ambiguity error in Visual Studio because the “invisible” Errors.cs from the NuGet package ran into the “visible” Errors.cs, which I manually added to the project.

+6
source

Source: https://habr.com/ru/post/1245001/


All Articles