0

I have a Visual Studio Build definition that compiles solution1.sln. It has 2 web projects: WebProject1, and WebApiProject2.

Is there any what to get those names (WebProject1, WebApiProject2) automatically into variables?

nerlijma
  • 935
  • 1
  • 9
  • 24

1 Answers1

0

You need to add a Powershell step to retrieve project names from a .sln file and then set the project names into variables.

Get project names:

Get-Content 'xxx.sln' |
  Select-String 'Project\(' |
    ForEach-Object {
      $projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') };
      New-Object PSObject -Property @{
        Name = $projectParts[1];

      }
    }

Sets a variable in the variable service of taskcontext. The first task can set a variable, and following tasks are able to use the variable. Check ##vso[task.setvariable]value for more information.

Example:

##vso[task.setvariable variable=testvar;]testvalue
##vso[task.setvariable variable=testvar;issecret=true;]testvalue
Community
  • 1
  • 1
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • can you explain how to set the variables? Is that part written in the same powershell as when getting the project names? – nerlijma May 06 '16 at 00:17
  • You can get projects name and set them into variable in one powershell. The variable will be exposed to the following tasks as an environment variable. – Cece Dong - MSFT May 06 '16 at 09:33