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>
totrue
. - 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.
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.
In the package, is readme.txt in the root directory? Is the package being installed directly (for example, using Package Manager) or as a dependency?