Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nuget pack on csproj for readme.txt not behaving as expected

Tags:

nuget

Is there a way to get nuget to pick up the readme.txt file included in a .csproj using "nuget pack " so that when the package is installed the readme.txt file opens up automatically in VS?

When I create the nuspec by hand and list the readme.txt in the section such that the readme.txt file resides at the same level as the nuspec file, running nuget pack on the nuspec does the right thing.

When using nuget pack on the .csproj though the behavior is such that the readme file of the project gets included in the "Content" folder instead. In this case, is there a way to get nuget pack to include the readme file in the section so that it behaves identical to creating the nuspec manually and adding the readme.txt at the root of the folder

like image 770
Abhijeet Patel Avatar asked Jan 17 '15 19:01

Abhijeet Patel


1 Answers

Yes, you need to do a few things. Let's assume your project is called MyProject.

  1. Make sure the Build Action (under Properties) for readme.txt is "None", not "Content". This prevents it from being placed under a \content folder when you package the csproj.
  2. If you don't already have a MyProject.nuspec file, create one in the same folder as MyProject.csproj. This should use the replacement tokens defined in Creating And Publishing A Package ($id$, $version$, etc.) to avoid duplicating anything specified in the project itself (e.g., in AssemblyInfo.cs).
  3. Add a <files> section in the nuspec file, containing only readme.txt, like this:
  <files>
    <file src="readme.txt" target="" />
  </files>

Having done this, when you run nuget pack MyProject.csproj, it will place readme.txt at the package root and will create the appropriate \lib folder for your DLL(s). Installing the package will open the readme.txt automatically without adding it to the target project as content.

I've tested this with NuGet 2.8.60717.93.

like image 195
Nick Jones Avatar answered Oct 21 '22 11:10

Nick Jones