【问题标题】:TFS Nuget Packager build step included the code(*.cs) files in the nupkg fileTFS Nuget Packager 构建步骤在 nupkg 文件中包含代码 (*.cs) 文件
【发布时间】:2017-08-04 11:31:55
【问题描述】:

在 TFS 中,我添加了一个步骤“Nuget Packager”。该项目构建良好,但是当我解压缩 nupkg 文件时,它包含项目文件(.csproj、.cs、*.config 文件)。我只希望二进制文件(例如 bin\Release*.dll 文件)。我在构建定义中遗漏了什么?

【问题讨论】:

  • 能分享一下“Nuget Packager”任务的详细设置吗?

标签: tfs tfsbuild


【解决方案1】:

更新

建议您在 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

【讨论】:

  • 我本来有,但没有帮助
  • @alltej 您可以打包 **\*.nuspec 文件而不是 .csproj 文件。通过创建 .nuspec 包清单。清单是一个 XML 文件,它描述包的内容,它本身包含在包中。有关如何使用 .nuspec 文件的更多详细信息,请参阅本教程:docs.microsoft.com/en-us/nuget/create-packages/…
  • 是的,我确实使用了 nuspec 文件。它是使用与 *.csproj 文件位于同一目录中的 nuget spec 创建的。
  • @alltej 手动使用nuget命令打包解压nupkg会有什么结果。这似乎与 TFS 无关,TFS 构建定义中没有其他设置。如果得到相同的结果,您需要自定义 .nuspec 文件,而不是使用默认的 .nuspec 文件。由于 NuGet 在创建包时会自动包含所有文件。
  • 所以我将 nuget pack 任务更改为使用 .csproj 文件。现在它只打包dll。所以看起来 TFS nuget 包(使用.nuspec)与本地 nuget 包(使用.nuspec)的行为不同。同样对于使用.csproj 的TFS nuget pack 任务,它使用.nuspec 中的值,就像版本一样。我期待,因为它使用.csproj,它会从AssemblyInfo.cs读取值
猜你喜欢
  • 2017-06-02
  • 1970-01-01
  • 2017-07-15
  • 2014-09-08
  • 2017-08-27
  • 2019-01-04
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
相关资源
最近更新 更多