【发布时间】:2020-09-24 10:43:29
【问题描述】:
我有一个带有 xml 文档文件 (doc.xml) 的 NuGet 包。
我已经在我的项目中安装了 NuGet 包。
我知道想将 NuGet 文档文件 doc.xml 添加到我的解决方案中。
我正在运行 .net core 3.1,但我不知道如何实现。
谢谢!
【问题讨论】:
-
嗨丹尼尔,关于这个问题的任何更新?
标签: visual-studio .net-core nuget
我有一个带有 xml 文档文件 (doc.xml) 的 NuGet 包。
我已经在我的项目中安装了 NuGet 包。
我知道想将 NuGet 文档文件 doc.xml 添加到我的解决方案中。
我正在运行 .net core 3.1,但我不知道如何实现。
谢谢!
【问题讨论】:
标签: visual-studio .net-core nuget
如果您的 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>
这个目标的建议是当你把这个nuget安装到主项目中时,将nupkg的File文件夹中的xml文件复制到目标项目的文件夹中。
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下的所有缓存文件来删除旧的,以防你仍然安装旧的。
之后,重建你的主项目来执行目标,你会看到xml文档文件存在于主项目文件夹下。
另外还有a similar issue you can refer to,如果你使用net framework项目,链接也提供了方法。
============================
更新 1
如果要将文件复制到bin\Release或bin\Debug,则应修改第2步,改为在.props文件中使用:
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(ProjectDir)$(OutputPath)"
/>
或者只是
<Copy
SourceFiles="@(SourceScripts)"
DestinationFolder="$(OutDir)"
/>
如你所愿。
在安装这个新版本之前,你应该先删除C:\Users\xxx(current user)\.nuget\packages下的nuget缓存。
【讨论】: