【发布时间】:2017-08-04 11:31:55
【问题描述】:
在 TFS 中,我添加了一个步骤“Nuget Packager”。该项目构建良好,但是当我解压缩 nupkg 文件时,它包含项目文件(.csproj、.cs、*.config 文件)。我只希望二进制文件(例如 bin\Release*.dll 文件)。我在构建定义中遗漏了什么?
【问题讨论】:
-
能分享一下“Nuget Packager”任务的详细设置吗?
在 TFS 中,我添加了一个步骤“Nuget Packager”。该项目构建良好,但是当我解压缩 nupkg 文件时,它包含项目文件(.csproj、.cs、*.config 文件)。我只希望二进制文件(例如 bin\Release*.dll 文件)。我在构建定义中遗漏了什么?
【问题讨论】:
更新
建议您在 Pack NuGet 任务的 要打包的 csproj 或 nuspec 文件的路径中使用 .csproj 而不是 **\*.nuspec。这将在 TFS 中获得与本地相同的结果。
通过 nuget spec 命令自动创建 .nuspec 包清单。 XML清单文件长这样:
<metadata>
<id>C:\Users\xx\Source\Workspaces\Workspace\TestNuGetPackager\TestNuGetPackager\xx.csproj</id>
<version>1.0.0</version>
<authors>xxx</authors>
<owners>xxx</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Tag1 Tag2</tags>
<dependencies>
<dependency id="SampleDependency" version="1.0" />
</dependencies>
</metadata>
</package>
您需要手动更改 .nuspec 文件的值,如下所示,包括详细的 dll 并硬编码一些信息
<package >
<metadata>
<id>TestNuGetPackager</id>
<version>1.0.0</version>
<authors>Test</authors>
<owners>Test</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="bin\Release\TestNuGetPackager.dll" target="lib\46"/>
</files>
</package>
在此之后您将获得唯一的二进制文件,否则使用系统自动生成的.nuspec 文件,您将打包包含项目文件。需要将修改后的.nuspec文件签入到TFS并再次触发构建。
更多.nuspec文件使用方法请参考本教程:The role and structure of the .nuspec file
【讨论】:
**\*.nuspec 文件而不是 .csproj 文件。通过创建 .nuspec 包清单。清单是一个 XML 文件,它描述包的内容,它本身包含在包中。有关如何使用 .nuspec 文件的更多详细信息,请参阅本教程:docs.microsoft.com/en-us/nuget/create-packages/…
nuget spec 创建的。
.nuspec 文件。由于 NuGet 在创建包时会自动包含所有文件。
.csproj 文件。现在它只打包dll。所以看起来 TFS nuget 包(使用.nuspec)与本地 nuget 包(使用.nuspec)的行为不同。同样对于使用.csproj 的TFS nuget pack 任务,它使用.nuspec 中的值,就像版本一样。我期待,因为它使用.csproj,它会从AssemblyInfo.cs读取值