Reputation: 1889
I want to create a NuGet package with some files in content, I want these files to be added to the project but not referenced by the project, hence they are not compiled. How would I go about this?
Thanks
Upvotes: 1
Views: 610
Reputation: 1354
Edit your nuspec file, putting in the references to your files like so:
<?xml version="1.0"?>
<package>
<metadata>
...
</metadata>
<files>
...
<file src="MyFirstContentFile.txt" target="content" />
<file src="MySecondContentFile.cs" target="content" />
...
</files>
</package>
The target="content" bit is what does the magic of copying the files into your project.
Now, if the files you are importing into the project are code files (e.g. .cs files), and you don't want them to be compiled, you need to set the build action of those files. To do this you need to do some work on the install.ps1 file (create one if you have not yet got one, and don't forget to reference the file in your files section with target="tools"):
param($installPath, $toolsPath, $package, $project)
$file1 = $project.ProjectItems.Item("MyFirstContentFile.txt")
$file2 = $project.ProjectItems.Item("MySecondContentFile.cs")
# set 'BuildAction' to 'Content'
$copyToOutput1 = $file1.Properties.Item("BuildAction")
$copyToOutput1.Value = 2
$copyToOutput2 = $file2.Properties.Item("BuildAction")
$copyToOutput2.Value = 2
See the following link for possible values of the BuildAction enum. http://msdn.microsoft.com/en-us/library/aa983962(VS.71).aspx
Upvotes: 1