Xml文档未打包在类库中

时间:2018-02-07 03:58:36

标签: c# xml visual-studio nuget nuget-package

我有两个项目,MyModels(包含类模型)和MyExample XML文件是在MyModels项目中创建的,很好。

现在在MyExample项目中,我通过nuget安装它来引用MyModels,但是如何在安装nuget包时将XML文档包含在包中? (它总是缺失)

1 个答案:

答案 0 :(得分:2)

  

Xml文档未打包在类库中

如果您使用的是常见的.csproj类型项目而不是基于SDK的&#34;,则可以使用{Route::post('facility', 'FacilityController@store') ->name('facility.store') ->middleware(['superAdmin', 'admin', 'tenantRelation', 'receptionist']); 节点直接包含XML文档以包含在包中1}}文件,位于<files>标记之后:

.nuspec

以下是我的<metadata>

  <files>
    <file src="bin\Debug\MyModels.dll" target="lib\Net45" />
    <file src="bin\Debug\MyModels.xml" target="lib\Net45" />
  </files>

然后build the package with this command

.nuspec

NuGet.exe成功创建了nupkg:

enter image description here

如果您使用新的.csproj类型项目(基于VS2017 SDK),则可以将<?xml version="1.0"?> <package > <metadata> <id>MyModels</id> <version>1.0.0</version> <authors>Tester</authors> <owners>Tester</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>Package description</description> <releaseNotes>Summary of changes made in this release of the package.</releaseNotes> <copyright>Copyright 2018</copyright> <tags>Tag1 Tag2</tags> </metadata> <files> <file src="bin\Debug\MyModels.dll" target="lib\Net45" /> <file src="bin\Debug\MyModels.xml" target="lib\Net45" /> </files> </package> 设置为csproj文件:

nuget pack MyModels.nuspec

使用选项GenerateDocumentationFile,MSBuild将包含nuget包中的所有生成文件。

此外,如果您希望将XML文档发送到<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <GenerateDocumentationFile>true</GenerateDocumentationFile> <GeneratePackageOnBuild>true</GeneratePackageOnBuild> </PropertyGroup> </Project> 项目,则可以将目标更改为内容:

GenerateDocumentationFile

希望这有帮助。

评论更新:

  

我使用的是.NET Core 2,它是一样的吗?

是的,您只需更新MyExample文件中的src和target:

  <files>
    <file src="bin\Debug\MyModels.dll" target="lib\Net45" />
    <file src="bin\Debug\MyModels.xml" target="Content\MyModels.xml" />
  </files>

或者您可以直接使用新的.nuspec类型项目(基于VS2017 SDK),将 <files> <file src="bin\Debug\netcoreapp2.0\MyModels.dll" target="lib\netcoreapp2.0" /> <file src="bin\Debug\netcoreapp2.0\MyModels.xml" target="lib\netcoreapp2.0" /> </files> 设置为.csproj文件,然后选中复选框&#34;生成NuGet包建立&#34;在项目属性的包选项卡上:

enter image description here

构建之后,在输出文件夹中生成nuget包:

enter image description here

注意:如果你想要将XML文档添加到MyExample的项目中,你应该使用内容文件:

https://docs.microsoft.com/en-us/nuget/reference/nuspec#including-assembly-files

希望这有帮助。