包含来自 NuGet 包的 XML 文档
include the XML documentation from a NuGet package
我有一个带有 xml 文档文件 (doc.xml) 的 NuGet 包。
我已经在我的项目中安装了 NuGet 包。
我知道要将 NuGet 文档文件 doc.xml 添加到我的解决方案中。
我是 运行 .net core 3.1 但我不知道如何实现。
谢谢!
如果您的 nuget 项目是 net standard
或 net core
,请检查以下步骤:
1) 在项目的 build 文件夹下创建一个名为 <package_id>.props
的文件。
注意,你应该确保你的nuget项目的package_id
与.props
文件相同,否则将无法运行。参见 this link's description。
在我这边,我的 nuget 包叫 test.1.0.0.nupkg
,所以我应该把文件重命名为 test.props
文件。
2)请在test.props
文件中添加这些内容。
<Project>
<Target Name="CopyFilesToProject" BeforeTargets="Build">
<ItemGroup>
<SourceScripts Include="$(MSBuildThisFileDirectory)..\File\*.*"/>
</ItemGroup>
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(ProjectDir)"
/>
</Target>
</Project>
这个target的提议是将nupkg的File文件夹中的xml文件复制到target中将此 nuget 安装到主项目时的项目文件夹。
3) 在 xxx.csproj
文件下添加:
<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) 然后,打包项目时,结构应该是这样的:
在安装这个新版本的nuget包之前,你应该clean nuget caches first或者只删除C:\Users\xxx(current user)\.nuget\packages
下的所有缓存文件以删除旧的如果你仍然安装旧的。
After that, rebuild你的主工程执行target你会看到xml文档文件存在于主项目文件夹。
除外,还有,如果使用net framework
项目,link也提供方法
===========================
更新 1
如果你想将文件复制到bin\Release
或bin\Debug
,你应该修改步骤2,改为在[=18]中使用这个=] 文件:
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(ProjectDir)$(OutputPath)"
/>
或者只是
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(OutDir)"
/>
如你所愿。
在安装这个新版本之前,您应该先删除C:\Users\xxx(current user)\.nuget\packages
.
下的nuget缓存
我有一个带有 xml 文档文件 (doc.xml) 的 NuGet 包。
我已经在我的项目中安装了 NuGet 包。
我知道要将 NuGet 文档文件 doc.xml 添加到我的解决方案中。
我是 运行 .net core 3.1 但我不知道如何实现。
谢谢!
如果您的 nuget 项目是 net standard
或 net core
,请检查以下步骤:
1) 在项目的 build 文件夹下创建一个名为 <package_id>.props
的文件。
注意,你应该确保你的nuget项目的package_id
与.props
文件相同,否则将无法运行。参见 this link's description。
在我这边,我的 nuget 包叫 test.1.0.0.nupkg
,所以我应该把文件重命名为 test.props
文件。
2)请在test.props
文件中添加这些内容。
<Project>
<Target Name="CopyFilesToProject" BeforeTargets="Build">
<ItemGroup>
<SourceScripts Include="$(MSBuildThisFileDirectory)..\File\*.*"/>
</ItemGroup>
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(ProjectDir)"
/>
</Target>
</Project>
这个target的提议是将nupkg的File文件夹中的xml文件复制到target中将此 nuget 安装到主项目时的项目文件夹。
3) 在 xxx.csproj
文件下添加:
<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) 然后,打包项目时,结构应该是这样的:
在安装这个新版本的nuget包之前,你应该clean nuget caches first或者只删除C:\Users\xxx(current user)\.nuget\packages
下的所有缓存文件以删除旧的如果你仍然安装旧的。
After that, rebuild你的主工程执行target你会看到xml文档文件存在于主项目文件夹。
除外,还有net framework
项目,link也提供方法
===========================
更新 1
如果你想将文件复制到bin\Release
或bin\Debug
,你应该修改步骤2,改为在[=18]中使用这个=] 文件:
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(ProjectDir)$(OutputPath)"
/>
或者只是
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(OutDir)"
/>
如你所愿。
在安装这个新版本之前,您应该先删除C:\Users\xxx(current user)\.nuget\packages
.