Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I build Visual Studio 2019 projects on Travis CI?

Travis CI recently added a Windows OS option to its build system. Unfortunately, the preinstalled packages only include Visual Studio 2017.

How can I build Visual Studio 2019 projects (such as .Net Core 3.1 and v142 build tools projects) on Travis?

like image 770
ladenedge Avatar asked Jan 25 '23 01:01

ladenedge


1 Answers

The key to using updated build tools is Chocolatey, the Windows package manager. As long as the toolset is available on Chocolatey, you can install it on your Travis VM.

For .Net Core, that means installing the dotnetcore-sdk package.

For VC++ build tools, there is the visualstudio2019buildtools package, but note you will have to opt in to the Microsoft.VisualStudio.Component.VC.Tools.x86.x64 feature. See below for syntax. A full list of features is available in the Build Tools component directory.

Here's a full .travis.yml file for a VS 2019 solution containing a C++ project, a .Net Standard 2.0 project and a .Net Core 3.1 project. The test project makes use of the unmanaged DLL.

os: windows
language: cpp
env:
  - MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin"
install:
  - choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
  - choco install dotnetcore-sdk
  - dotnet restore
script:
  - export PATH=$MSBUILD_PATH:$PATH
  - MSBuild.exe -p:Configuration=Release -p:Platform=x64 CppProject/CppProject.vcxproj
  - dotnet build --configuration Release
  - dotnet test DotNetProject.Tests/bin/Release/netcoreapp3.1/DotNetProject.Tests.dll
like image 186
ladenedge Avatar answered Feb 22 '23 22:02

ladenedge