.Net Core .csproj – Automatically Packaging README.txt

, , , ,

Microsoft Visual Studio gives special treatment to a README.txt file found in a NuGet package’s root directory. If README.txt is present in this folder, Visual Studio displays its contents when the package is directly installed (vs. when it is installed as a dependency).

This sounds like a great way to display notes and examples to the developer getting ready to use your package—but how do you get a readme file copied from your project into the package during the packaging process?

Automating this requires a little csproj editing.

Your csproj file will need a <Content> element for your text file. If one doesn’t already exist, create one. The element’s Include attribute should be the path to the text file, relative to the project’s root directory.

Inside the <Content> element:

  • Indicate that the file should be included in the package by setting <Pack> to true.
  • Specify the location where the file should go in the package by setting <PackagePath> (this path is relative to the package’s root directory).
    <Content Include="README.txt">

Easy enough! With these packaging configuration settings in place, your readme file should be placed in the package in the proper place each time you trigger packaging.

2 thoughts on “.Net Core .csproj – Automatically Packaging README.txt

  1. Ilangeeran

    I have a nuget package created by me. That solution has a readme.txt. I have included that in the csproj file.
    But after getting the package in another solution to test it, i dont find the readme file in the visual studio.


Leave a Reply

Your email address will not be published. Required fields are marked *