Reputation:
I have a NuGet package with an xml documentation file (doc.xml).
I have installed the NuGet package in my project.
I know want to add the NuGet documentation file doc.xml to my solution.
I am running .net core 3.1 but I have no idea how this can be achieved.
Thank you!
Upvotes: 2
Views: 1924
Reputation: 23740
If your nuget project is net standard
or net core
, please check these steps:
1) create a file called <package_id>.props
file under a folder called build on your project.
Note that, you should make sure that the your package_id
of your nuget project is the same as the .props
file, otherwise, it will not work. See this link's description.
In my side, my nuget package called test.1.0.0.nupkg
, so I should rename the file as test.props
file.
2) please add these content in test.props
file.
<Project>
<Target Name="CopyFilesToProject" BeforeTargets="Build">
<ItemGroup>
<SourceScripts Include="$(MSBuildThisFileDirectory)..\File\*.*"/>
</ItemGroup>
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(ProjectDir)"
/>
</Target>
</Project>
The propose of this target is to copy the xml file from the File folder of the nupkg into the target project's folder when you install this nuget into the main project.
3) add these under xxx.csproj
file:
<ItemGroup>
<None Include="bin\Debug\netcoreapp3.1\test.xml(the path of the xml file in your nuget project)" Pack="true" PackagePath="File"></None>
<None Include="build\test.props(the path of the test.props file in your nuget project)" Pack="true" PackagePath="build"></None>
</ItemGroup>
4) Then, when you pack your project, the structure should be this:
Before you install this new version of nuget package, you should clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages
to remove the old ones in case you still install the old one.
After that, rebuild your main project to execute the target and you will see the xml document file exist under the main project folder.
In addition, there is a similar issue you can refer to and if you use the net framework
project, the link also provide the method.
===========================
Update 1
If you want to copy the file into bin\Release
or bin\Debug
, you should modify step 2, change to use this in the .props
file:
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(ProjectDir)$(OutputPath)"
/>
or just
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(OutDir)"
/>
as you want.
Before you install this new version, you should first delete nuget caches under C:\Users\xxx(current user)\.nuget\packages
.
Upvotes: 3