2

I have a C++ project that has cpprestsdk and libpqxx as its dependencies and I'm using vcpkg as my package manager.

I've created an Azure DevOps pipeline that uses the CppBuildTask task to clone and build the dependencies from vcpkg, this is working correctly and all the dependencies are pulled and built successfully, but I'm not sure how to actually build the project using the *.vcxproj file.

I tried using the Visual Studio Build task, but the build fails because it can't find the dependencies that were just downloaded by the CppBuildTask.

What is the correct task to use when trying to build a MSVC++ project with vcpkg on Azure DevOps?

Edit, the pipeline yaml file:

pool:
  name: Azure Pipelines
demands:
  - msbuild
  - visualstudio

steps:
  - task: Cache@2
    displayName: Cache
  inputs:
    key: '$(Build.SourcesDirectory)/response_file.txt | 5951e0b42569257f97a5d9ac2d8c5bd4942c417b | x64-windows'
    path: '$(Build.SourcesDirectory)/vcpkg'

- task: lucappa.cmake-ninja-vcpkg-tasks.d855c326-b1c0-4d6f-b1c7-440ade6835fb.run-vcpkg@0
  displayName: 'Run vcpkg'
  inputs:
    vcpkgDirectory: '$(Build.SourcesDirectory)/vcpkg'
    vcpkgGitCommitId: 5951e0b42569257f97a5d9ac2d8c5bd4942c417b
    vcpkgArguments: '@$(Build.SourcesDirectory)/response_file.txt'
    cleanAfterBuild: false

- task: VSBuild@1
  displayName: 'Build solution TileServer\TileServer.vcxproj'
  inputs:
    solution: '$(Parameters.solution)'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    msbuildArchitecture: x64

- task: PublishSymbols@2
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
    IndexSources: false
    PublishSymbols: false
  continueOnError: true

 - task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
  inputs:
    Contents: |
     **\bin\$(BuildConfiguration)\**
     .\Renderer\Styles\Themes\DefaultTheme.json
     .\TileServer\glew32.dll
     .\TileServer\ReleaseSettings.json

    TargetFolder: '$(build.artifactstagingdirectory)'
  condition: succeededOrFailed()

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
    ArtifactName: TileServer
  condition: succeededOrFailed()
Walter
  • 664
  • 1
  • 6
  • 19
  • As normal, vsbuild task is enough. Do you mind update with how do you configure the pipeline? Share the complete pipeline structure would be great for others member to find issue cause. – Mengdi Liang Mar 30 '20 at 09:46
  • I've included the yaml file for the pipeline – Walter Mar 30 '20 at 10:22
  • Thanks! Does the dependencies that error message prompt is `SDL\SDL.vcxproj` and `SDLmain\SDLmain.vcxproj` not found? – Mengdi Liang Mar 30 '20 at 14:25
  • No, the only build errors I get are Error C1083: Cannot open include file: 'pqxx/pqxx': No such file or directory and Error C1083: Cannot open include file: 'cpprest/http_listener.h': No such file or directory – Walter Mar 30 '20 at 14:38
  • Just confirming, which vmimage your pipeline is picking? windows 2019? or vs2017? In addition, what is your build platform and configuration value? Did you ever check the path of actual dependencies pulled location by comparing with the header your file? – Mengdi Liang Mar 30 '20 at 15:24
  • It's windows2019 and x64-windows release build. In terms of the locations of the dependencies, I think this is where I'm getting stuck, on my development computer, the vcpkg location is picked up automatically by visual studio, so when I include the headers I do like so `#include ` and `#include `. This works fine on my dev machine. But I'm not sure if the msbuild instance in the pipeline is picking up the vcpkg directory. – Walter Mar 30 '20 at 15:39
  • I’m afraid no, azure pipeline could not know that vcpkg path automatically. I think we need find something available. For me, I specify the vcpkg path with hard code into **additional include directory**, so that the headers could include successfully. How about you? – Mengdi Liang Mar 31 '20 at 11:38
  • 1
    Well, that would mean the directory for my packages on development machines would have to be the same as the build server. That seems unusual, I was hoping there would be a way to tell msbuild where to find dependencies, similar to the way VS does on our dev machines. – Walter Apr 01 '20 at 11:17
  • I have one idea, since msbuild.exe support to read system environment variables, what about add one command line task before your VSbuild task to set environment variable `set "INCLUDE=%additional_include_path%;%INCLUDE%" set "LIB=%additional_lib_path%;%LIB%"`? Then it could make the same effect with the option of VS. – Mengdi Liang Apr 02 '20 at 09:46

1 Answers1

0

I was able to get vcpkg to work properly by explicitly integrating it after running the install command. Add this after the run-vcpkg task and that should fix it:

- task: CmdLine@2
  inputs:
    script: '$(VCPKG_ROOT)\vcpkg.exe integrate install'