【问题标题】:Building nuget file from nuspec with Azure Pipelines使用 Azure Pipelines 从 nuspec 构建 nuget 文件
【发布时间】:2020-01-28 17:50:53
【问题描述】:

我遇到了一个奇怪的问题,并且已经尝试修复了几天。在本地,我可以使用以下 nuspec 文件很好地构建我的项目。 nuspec 文件保存在 repo 中,并在从 c# 项目构建时复制到本地,它位于名为“nugetcreation”的子文件夹下。在本地,我可以按原样运行 nuspec 文件并生成 nuget 包。

文件夹设置: 项目 -项目文件 -nugetcreation -readme 和 nuspec 文件

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>my.Utility.TraceWriter</id>
    <version>1.0.0-beta</version>
    <title>my.Utility.TraceWriter</title>
    <authors>justme</authors>
    <owners>justme</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>custom trace items</description>
    <releaseNotes>initial release</releaseNotes>
  </metadata>
  <files>
    <file src="Content\MyReadMes\My.Utility.TraceWriter.md" target="content\net461\MyReadMes\My.Utility.TraceWriter.md" />
    <file src="..\My.Utility.TraceWriter.dll" target="lib\net461\My.Utility.TraceWriter.dll" />
    <file src="..\My.Utility.TraceWriter.pdb" target="lib\net461\My.Utility.TraceWriter.pdb" />
  </files>
</package>

问题: 在构建 Azure Pipeline 时,我告诉它运行 nuspec 文件,但出现错误

##[error]The nuget command failed with exit code(1) and error(Error NU5019: File not found: '..\My.Utility.TraceWriter.dll'.

但它绝对是从 vsbuild 过程中正确生成的

CopyFilesToOutputDirectory:
  Copying file from "d:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\obj\Release\My.Utility.TraceWriter.dll" to "d:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\bin\Release\My.Utility.TraceWriter.dll"

Azure 管道中的 nuget 创建步骤非常基本,没有什么花哨的。我保存在 nuspec 文件中的所有花哨的东西。我试图让它在一个带有 nuspec 文件的基本项目上工作,因为我稍后会有更复杂的 nuget 打包,所以这是我的测试版本。

- task: NuGetCommand@2
  displayName: 'Creating nuget package'
  inputs:
    command: 'pack'
    packagesToPack: '**/*.nuspec'
    versioningScheme: 'off'
    arguments: '--configuration $(buildConfiguration)'

到目前为止,我已经尝试过使用:

  • **\My.Utility.TraceWriter.dll (没有错误,但 lib 文件夹中没有 dll。就像刚刚跳过该行一样)
  • bin**\My.Utility.TraceWriter.dll
  • .\My.Utility.TraceWriter.dll
  • $configuration$\My.Utility.TraceWriter.dll
  • **\$configuration$\My.Utility.TraceWriter.dll

...没有任何作用。有没有人知道为什么天蓝色管道不接受 nuspec 文件上正确的 (..\My.Utility.TraceWriter.dll) 相对路径条目以及如何修复它?

我的前额因为敲击键盘而受伤......

--编辑--

更多信息。运行 nuget pack 命令时,似乎发生了两件事。整个输出如下,但看起来nuget成功构建后它正在尝试再次打包它,这次找不到文件??

Added file '_rels/.rels'.
Added file 'My.Utility.TraceWriter.nuspec'.
Added file 'content/net461/MyReadMes/My.Utility.TraceWriter.md'.
Added file 'lib/net461/My.Utility.TraceWriter.dll'.
Added file 'lib/net461/My.Utility.TraceWriter.pdb'.
Added file 'package/services/metadata/core-properties/f2a4d059fea6458dac5889de57641f5b.psmdcp'.

Successfully created package 'D:\a\1\a\My.Utility.TraceWriter.1.0.0-beta.nupkg'.
WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below:
- Add a dependency group for .NETFramework4.6.1 to the nuspec
Attempting to pack file: D:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\nuget information\My.Utility.TraceWriter.nuspec
C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe pack "D:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\nuget information\My.Utility.TraceWriter.nuspec" -NonInteractive -OutputDirectory D:\a\1\a -Properties Configuration=Release -Verbosity Detailed
Error NU5019: File not found: '..\My.Utility.TraceWriter.dll'.
NuGet Version: 5.4.0.6315
NuGet.Packaging.Core.PackagingException: File not found: '..\My.Utility.TraceWriter.dll'.

【问题讨论】:

    标签: azure-devops nuspec


    【解决方案1】:

    愚蠢。 packagesToPack: '**/*.nuspec' 正在拉取两个 nuspec:源中的一个和复制到输出 bin 文件夹的一个。

    重新定义解决了问题

    【讨论】:

    • 太棒了!感谢您在这里分享您的解决方案,您可以 Accept it as an Answer ,这样它可以帮助遇到相同问题的其他社区成员,我们可以存档这个帖子,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 2019-02-18
    相关资源
    最近更新 更多