-1

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?

zep426
  • 179
  • 9
  • What steps have you taken to troubleshoot? Did you try running restore with *just* the `webProject` variable, then *just* the `dbProject` variable? Did you confirm that the value specified in the `dbProject` variable corresponds to a file that is actually present in your agent's working directory? Etc – Daniel Mann Jun 29 '22 at 15:22
  • @DanielMann I am able to get it working if I replace the variable text and I can see the file in the working directory and it matches the value of the variable. I can get the restore to work with separate tasks....although I would like to know why the variables are not working as one would expect. – zep426 Jun 29 '22 at 15:34
  • @DanielMann Additionally, as this might be helpful....But I originally built this file without using variables just to get it working. It was working fine when I hard coded the values as I stated before. It was just when I started extracting values to variables and used them for the projects argument of the dotnet cli tasks that I started receiving the error. – zep426 Jun 29 '22 at 15:38

3 Answers3

1

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
Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • Unfortunately, for my case I really needed a way to include only specific projects and avoid hard coding for making a template. I was able to get it working and posted an answer, perhaps it helps you in the future should you find yourself in my shoes. – zep426 Jun 29 '22 at 22:15
1

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'
   
zep426
  • 179
  • 9
-1

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)"'
Shachar297
  • 599
  • 2
  • 7