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.
- Indicate that the file should be included in the package by setting
- Specify the location where the file should go in the package by setting
<PackagePath>(this path is relative to the package’s root directory).
<Project> … <ItemGroup> <Content Include="README.txt"> <Pack>true</Pack> <PackagePath>README.txt</PackagePath> </Content> </ItemGroup> … </Project>
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.