Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can NuGet add a .cs file to the destination project?

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".

like image 923
lance Avatar asked May 28 '12 13:05

lance


People also ask

How use NuGet package in C# project?

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.

Where do I put Nuspec files?

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.


2 Answers

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

like image 165
Alexandre Dion Avatar answered Oct 04 '22 20:10

Alexandre Dion


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> 
like image 24
Luk Avatar answered Oct 04 '22 19:10

Luk