Azure Pipeline将在Dotnet CLI任务中识别变量

发布于 2025-02-11 18:29:51 字数 703 浏览 3 评论 0原文

我为管道有这些变量:

variables:
  webProject: 'Company.Web'
  dbProject: 'Company.Database'

然后,后来,我在dotnet cli任务中使用这些变量:

# stage/job setup
- task: DotNetCoreCLI@2
  displayName: Clean
  inputs:
    command: custom
    projects: '**/$(webProject).csproj'
    custom: clean
    arguments: '--configuration "$(BuildConfiguration)"'
- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: custom
    custom: restore
    projects: | 
      '**/$(webProject).csproj'
      '**/$(dbProject).csproj'
# rest of yaml

当我运行管道时,我会发现此错误:找不到匹配指定模式的项目文件。

奇怪的是,它对干净的任务有效,但是还原失败。我能够使用回声脚本确认变量正确渲染。我还可以用脚本中的变量文本替换变量,并且在这样做时运行良好。知道我在这里缺少什么吗?

I have these variables for my pipeline:

variables:
  webProject: 'Company.Web'
  dbProject: 'Company.Database'

And then later, I use those variables in a dotnet cli task:

# stage/job setup
- task: DotNetCoreCLI@2
  displayName: Clean
  inputs:
    command: custom
    projects: '**/$(webProject).csproj'
    custom: clean
    arguments: '--configuration "$(BuildConfiguration)"'
- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: custom
    custom: restore
    projects: | 
      '**/$(webProject).csproj'
      '**/$(dbProject).csproj'
# rest of yaml

When I run the pipeline, I get this error: Project file(s) matching the specified pattern were not found.

What is strange is it works ok for the clean task, but the restore fails. I was able to confirm with a echo script the variable is being rendered correctly. I also am able to replace the variable with the variable text in the script and it runs just fine when I do that. Any idea what I am missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瞳孔里扚悲伤 2025-02-18 18:29:51

Although the documentation doesn't specifically state this, I'm expecting it's because you're including two glob patterns. You can either try **/*.csproj, or include two relative path with no wildcard characters, i.e.

src/Foo.csproj
src/Bar.csproj
孤凫 2025-02-18 18:29:51

在文档中,有一个扩展地球解释了如何匹配多个项目。

如果您像我一样,只需要针对特定​​项目(仍在使用通配符)运行命令并保留变量/参数以进行模板,那么这就是要走的方法。

它如何对我有用:

- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: custom
    custom: restore
    projects: '**/*($(dbProject)|$(webProject)).csproj'
   

In the documentation there is a section for Extended Globbing that explains how to match multiple projects.

If you are like me and only need to run a command against specific projects (while still using wildcards) and preserve variables/parameters for templating, this is the way to go.

How it worked for me:

- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: custom
    custom: restore
    projects: '**/*($(dbProject)|$(webProject)).csproj'
   
十年不长 2025-02-18 18:29:51

如果使用模板,请尝试使用此sintax

  inputs:
    command: custom
    projects: ${{ variables.webProject }}
    custom: clean
    arguments: '--configuration "$(BuildConfiguration)"'

传递变量。

  • ,则应将变量作为azure-pipelines.yml azure-pipelines.yml
  - template: myTemplate.yml
    parameters: 
      projects : ${{ variables.webProject }}
  • mytemplate.yml
- task: DotNetCoreCLI@2
  displayName: Clean
  inputs:
    command: custom
    projects: "${{ parameters.webProject }}".csproj
    custom: clean
    arguments: '--configuration "$(BuildConfiguration)"'

Try to use this sintax

  inputs:
    command: custom
    projects: ${{ variables.webProject }}
    custom: clean
    arguments: '--configuration "$(BuildConfiguration)"'

If you use templates, then you should pass the variable as a parameters from the azure-pipelines.yml

  • azure-pipelines.yml
  - template: myTemplate.yml
    parameters: 
      projects : ${{ variables.webProject }}
  • myTemplate.yml
- task: DotNetCoreCLI@2
  displayName: Clean
  inputs:
    command: custom
    projects: "${{ parameters.webProject }}".csproj
    custom: clean
    arguments: '--configuration "$(BuildConfiguration)"'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文