I want to create a NuGet package that adds a .cs file (a base class the package consumer is encouraged to later modify) to the root of the destination project during installation.
Is that possible? Everything I've found so far says "no, you can only install files below the package's directory".
Step 1 - Select Tools > NuGet Package Manager > Package Manager Console. It will open a console in the bottom of the window. Step 2 - Select your project and execute the command to install the package. If it's a valid command, then the package will be installed to your project.
When the question is: Where do i put the nuspec within the package? the answer is: In the root folder of the package: Otherwise the answer is already answered by the other answer.
Just put your .cs file in a folder called "content", at the root of the package.
from the docs:
"you can layout a directory structure that follows the NuGet conventions.
tools - The tools folder of a package is for PowerShell scripts and programs accessible from the Package Manager Console. After the folder is copied to the target project, it is added to the `$env:Path (PATH) environment variable.
lib - Assemblies (.dll files) in the lib folder are added as assembly references when the package is installed.
content - Files in the content folder are copied to the root of your application when the package is installed.
Think of the Content folder as the root of your target application. For example, if I want a package to add an image in the /images directory of the target application, make sure to place the image in the Content/images folder of the package."
see: http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory
You can also use the <files>
section of the nuspec to move your file into the content folder when the package is being built:
<?xml version="1.0"?> <package> <metadata> ... </metadata> <files> <file src="App.Template.config" target="content" /> <file src="Program.template.cs" target="content" /> </files> </package>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With