1

I have this yaml pipeline in Azure DevOps:

variables:
  solution: 'fph.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- xxxx

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /t:FPH_Api\FPH_Api_csproj;Rebuild'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

The solution contain multiple projects and I am hoping that by providing DesktopBuildPackageLocation parameter and target parameter FPH_Api\FPH_Api_csproj;Rebuild, VSBuild will rebuild my web api project (so will rebuild other referenced projects as well) and then automatically zip the build into webapp.zip.

However, I got this error:

FPH_Api\FPH_Api_csproj" does not exist in the project.

I replaced the dots in FPH.API\FPH.api.csproj with underscores as dot is a forbidden character and tried several combinations like FPH_Api\FPH_Api or FPH_Api, but got the same error message.

Detail error shows this:

Project "D:\a\1\s\fph.sln" (1) is building "D:\a\1\s\FPH.Api\FPH.Api.csproj" (2) on node 1 (FPH_Api\FPH_Api_csproj target(s)).
D:\a\1\s\FPH.Api\FPH.Api.csproj : error MSB4057: The target "FPH_Api\FPH_Api_csproj" does not exist in the project.
Done Building Project "D:\a\1\s\FPH.Api\FPH.Api.csproj" (FPH_Api\FPH_Api_csproj target(s)) -- FAILED.

Seems the way I am doing things is not correct. So is it possible to use the VSBuild task to build a project in a solution and automatically zip the output?

riQQ
  • 9,878
  • 7
  • 49
  • 66
daxu
  • 3,514
  • 5
  • 38
  • 76

2 Answers2

2

I could reproduce your issue in my pipeline.

enter image description here

To solve this issue, you could define the target to folder level instead of csproj file level.

For example:

File structure:(csproj file is under Sample.WebAPI folder)

enter image description here

argument: /t:Sample_WebApi:Rebuild

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"   /t:Sample_WebApi:Rebuild'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

For more info, you could refer to this doc about How to: Build specific targets in solutions by using MSBuild.exe

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
2

I realise that this is an old question but I have just been through similar pain trying to build a specific project from my solution using the msbuild targets argument. The answer was buried in this stack overflow thread specify project file of a solution using msbuild but it still took me a while to work out.

The msbuild /t parameter does not want file path and file name. Instead it requires the solution folder structure and the name of the project.

  1. Optional: solution folder structure
  2. Project name
  3. wrapped in double quotes if there are any spaces in the parameter
  4. Periods replaced with underscores.

For example if I have added FPH.Api project within a second level solution folder (e.g. Top Level > Second Level > FPH.Api) then I will see something like this in the .SLN file

Project("{guid}") = "Top Level", "Top Level", "{guid}"
EndProject
Project("{guid}") = "Second Level", "Second Level", "{guid}"
EndProject
Project("{guid}") = "FPH.Api", "FPH.Api\FPH.Api.csproj", "{guid}"
EndProject

In this case you would construct the /t parameter value as:

/t:"Top Level\Second Level\FPH_Api"

I hope that is helpful.