Marcus Ferron
Marcus Ferron

Reputation: 11

How do you build individual project artifacts in azure deveops pipeline

I have multiple projects contained in my repo that I would like to build individual zip artifact to deploy them each separately. Currently, the pipeline builds one zip artifact that contains all the projects. How do I configure my azure-pipelines.yml file to accomplish this task? Below is my current file.

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- 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" 
/p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

Upvotes: 1

Views: 1027

Answers (2)

LoLance
LoLance

Reputation: 28086

It depends on how you define the MSBuild arguments. The /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site" is the direct cause of the issue, it calls msbuild to package all projects into one WebApp.zip file.

With msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"' you can have separate ProjectName.zip files under $(build.artifactStagingDirectory) path.

And then you can use one Publish Build Artifact task to publish whole $(build.artifactStagingDirectory) directory which contains ProjectA.zip, ProjectB.zip...

Also you can use several Publish Build Artifact tasks in one pipeline for your several output xx.zip files.

Upvotes: 1

scotty3
scotty3

Reputation: 153

You can change the build parameter /p:PackageAsSingleFile=false which will prevent all the projects from being zipped together. If you want to move the built files after the build, before the Publish Artifacts step, you can create a Copy files task that will copy the project's build folder to another location within the '$(Build.ArtifactStagingDirectory)'

steps:

  • task: CopyFiles@2 displayName: 'Copy Project Files' inputs: SourceFolder: '$\ProjectName\bin$(BuildConfiguration)' Contents: '****' TargetFolder: '$(build.artifactstagingdirectory)\ProjectName' CleanTargetFolder: true

Though these will all still be placed within the 'drop' folder or whatever the $(build.artifactstagingdirectory) is called. The only way to separate artifacts is to create separate pipelines for each project.

Upvotes: 0

Related Questions