首页 > 解决方案 > 在 Azure DevOps 构建管道中传递 NuGet 'Pack' 参数

问题描述

在我的 Azure DevOps 构建管道中,我添加了一个打包命令类型(版本 2.*)的 NuGet 任务。

我正在尝试传递-Exclude ***.tt参数,以便在从其他项目引用时排除这些文件。但是,在生成的 NuGet 包中,这些 .tt 文件出现在 Content 文件夹中。

主机日志中写入的命令为:

nuget.exe pack PROJECTNAME.csproj -NonInteractive -OutputDirectory SOME_OUTPUTPATH -Properties "Configuration=release;\"-Exclude ***.tt\"" -Verbosity Detailed

如您所见, exclude 不是属性的一部分,但应该作为单独的-Exclude参数。

知道如何实现这一目标吗?非常感谢!

添加了截图和 YAML:

在此处输入图像描述

steps:
- task: NuGetCommand@2
  displayName: 'NuGet pack'
  inputs:
    command: pack
    packagesToPack: ProjectName.csproj
    buildProperties: '-Exclude ***.tt'

标签: azure-devopsnugetnuget-packageazure-pipelines

解决方案


当您使用-Exclude时,nuget pack .csproj您需要提供排除文件的完整路径。但是这里还有另一个问题,Azure DevOps 将 附加-Exclude-Properties并且它忽略了排除,所以我们需要以-Exclude另一种方式添加,如何?在 NuGetcustom命令中:

- task: NuGetCommand@2
  inputs:
    command: custom
    arguments: 'pack "$(Build.SourcesDirectory)\Path\To\.csproj" -Exclude "$(Build.SourcesDirectory)\Path\to\*.tt"'

这是您尝试的常规日志-Exclude,您可以看到 nuget 打包了我的.exe文件:

在此处输入图像描述

在我制作自定义命令后,这里有一个日志,没有.exe

在此处输入图像描述

我的任务是:

- task: NuGetCommand@2
  inputs:
    command: custom
    arguments: 'pack "$(Build.SourcesDirectory)\TestVars\TestVars\TestVars.csproj" -Exclude "$(Build.SourcesDirectory)\TestVars\TestVars\bin\Debug\*.exe"'

推荐阅读