Reputation: 161
After reading everything I could find about the new contentFiles
element of NuGet 3.3+, I still can't manage to make it work in my package. I've got a package that targets both net46
and uap10.0
, and the selection of the right DLLs for the project type and platform work as expected. But I would also like to add two files to the project on package installation, one CSV file for all projects and platforms, and one code file for either C# or VB.Net (with buildAction="Compile"
). Here's the abridged 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 does contain the three files in the contentFiles folder with the specified directory structure.
But when I install the package - I tried it with with both an Universal App (C# and VB) and a .NET 4.6 console app I modified to use a project.json
file - the reference to the DLL is added, but the content files are neither added to the project structure, nor copied into the project directory.
I am thankful for any input!
Upvotes: 8
Views: 2252
Reputation: 161
OK, I found that the contentFiles are actually working, but not in the way I expected it to. A short description for everybody who couldn't find his/her contentFiles:
Errors
class was accessible, although it wasn't visible anywhere in the project.I'm not sure if I like this new mechanism. Code coming from some invisible source I cannot see in Visual Studio (a library shipped via NuGet is visible in References, any code it brings via contentFiles is not) may pose problems at times. I actually discovered that the contentFiles mechanism is working when I got an ambiguity error in Visual Studio because the "invisible" Errors.cs from the NuGet package collided with the "visible" Errors.cs I had added to the project manually.
Upvotes: 8