You want to setup AppVeyor to build your VSTO project but you don’t know where to start? No problem. Get ready to follow the steps I followed when I faced the same issue.

First of all, I would like to provide you with the thread from AppVeyor’s support forum so you get the context of this post.

And now, let’s get dirty.

1. Creating a .zip file with VSTO dlls

First of all, we have to create a .zip file containing all the VSTO dlls that we’re going to need. If you feel lazy, you can download the VSTO file for v.14 (Outlook 2013) here. If you feel like you want to try it yourself then you should have to follow these instructions:

  1. Get 7z installed in your pc.
  2. Open your CMD.
  3. Execute the following commands:
    7z a vsto-pack.zip "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.Tools.Applications.BuildTasks.dll"
    
    7z a vsto-pack.zip "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.Tools.Office.BuildTasks\v4.0_14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Tools.Office.BuildTasks.dll"
    
    7z a vsto-pack.zip "c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets"
    
    7z a vsto-pack.zip "c:\Program Files\MSBuild\Microsoft.VisualStudio.OfficeTools.targets"
    
    7z a vsto-pack.zip "c:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\Bootstrapper\Packages\VSTOR40\*"
    
  4. You will end up with a file named vsto-pack.zip in your folder of choice. Now you have to upload it somewhere in order to download it via script when your build process starts.

 

2. Signing the project with a valid certificate

As you may already know you will have to sign your Outlook plugin with a valid certificate and you need it to be accessible when building the solution. But, how to accomplish this with AppVeyor? Well, you will have to access to your certificate via your own repository or download it from somewhere before building. In my case, I have the .pfx file included in my Github repository.

What we need to do is to set the password of the .pfx file in your Appveyor configuration. Go to Settings > Environment, add a new variable with the name you want (in the picture below is “certificatePass”), set the password and click over the padlock so it gets encrypted.

appveyor certificate password

It is very important that you encrypt the password. Otherwise, if you publish your appveyor.yml file, it will get exposed to anyone along with your .pfx file. You can figure out the consequences of such a combination… Later, in our script, we will decrypt the password, so no worries. Let’s move to the next paragraph.

3. Preparing your build script with PowerShell

Go to Settings > Build.

In my case, I’m going to use a PowerShell Script for all the process but you can take the pieces from the script below and put them into Pre and Post build scripts:

appveyor post y pre build script

In order to use just a unique script you’ll have to select “Script” and then insert your Powershell script there:

appveyor build script

Find below the full script with comments:

#HELPER FUNCTIONS
function log ($o){
    Write-host $o
}

function copyfile($from, $to){
    if (!(Test-Path -path $to)) {New-Item $to -Type Directory}
    Copy-Item $from -Destination $to -recurse
}

function execTest($config){
    $result = nunit-console.exe ("C:\projects\{your-project-path}\bin\" + $config + "\{your-test-dll-name}.dll") /include=UnitTest
    $test = select-string -pattern "Errors and Failures" -InputObject $result
    if($test.length){
        Write-Error ($config + " Tests are not passing!!") -Category InvalidResult
        $host.SetShouldExit(1)
    }
}

#RESTORING NUGET PACKAGES
log "#### RESTORING NUGET PACKAGES"
nuget restore

#DOWNLOADING VSTO DLLS
log "#### DOWNLOADING VSTO DLLS"
appveyor DownloadFile http://downloads.codecoding.com/redbooth/vsto-pack.zip

#UNZIPPING VSTO DLLS
log "#### UNZIPPING VSTO DLLS"
7z x -oC:\ vsto-pack.zip

#INSTALLING VSTO DLLS INTO THE GAC
log "#### INSTALLING DLLS INTO THE GAC"
$gac="C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil"
& $gac /i C:\Microsoft.VisualStudio.Tools.Applications.BuildTasks.dll
& $gac /i C:\Microsoft.VisualStudio.Tools.Office.BuildTasks.dll

#COPYING VSTO DLLS and Targets to the right place
log "#### COPYING TARGETS AND DLLS"
# c:\Program Files\MSBuild\Microsoft.VisualStudio.OfficeTools.targets
copyfile "C:\Microsoft.VisualStudio.OfficeTools.targets" "C:\Program Files\MSBuild\"
# c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets
copyfile "C:\Microsoft.VisualStudio.Tools.Office.targets" "c:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\OfficeTools\"
# C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages\VSTOR40\en
copyfile "C:\en" "C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages\VSTOR40\"
# C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages\VSTOR40\product.xml
copyfile "C:\product.xml" "C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper\Packages\VSTOR40\"

#GETTING THE SIGNING CERTIFICATE'S ENCRYPTED PASSWORD
log "#### GETTING THE SIGNING CERTIFICATE'S ENCRYPTED PASSWORD"
$psw = ConvertTo-SecureString $env:certificatePass -AsPlainText -Force

#IMPORTING THE CERTIFICATE TO USER STORE
log "#### IMPORTING THE CERTIFICATE TO USER STORE"
Import-PfxCertificate -FilePath .\{Path-to-your-pfx-in-your-github-project}\Certificate.pfx -CertStoreLocation cert:\CurrentUser\My -Password $psw

log "#### END PRE-BUILD PHASE ####"
log "#################"

#BUILD QA
log "#### TESTING QA"
msbuild "{your-solution-name}.sln" /p:Platform="Any CPU" /p:Configuration=QA /verbosity:minimal
execTest "QA"

log "#### BUILDING QA"
msbuild "{your-solution-name}.sln" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /t:Publish /p:Platform="Any CPU" /p:Configuration=QA /p:DeployOnBuild=true /p:InstallUrl="" /p:ApplicationVersion="$env:APPVEYOR_BUILD_VERSION" /verbosity:minimal

#BUILD RELEASE
log "#### TESTING RELEASE"
msbuild "{your-solution-name}.sln" /p:Platform="Any CPU" /p:Configuration=Release /verbosity:minimal
execTest "Release"

log "#### BUILDING RELEASE"
msbuild "{your-solution-name}.sln" /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /t:Publish /p:Platform="Any CPU" /p:Configuration=Release /p:DeployOnBuild=true /p:InstallUrl="{your-clickonce-installation-url}" /p:ApplicationVersion="$env:APPVEYOR_BUILD_VERSION" /verbosity:minimal

You maybe have noticed that I built the solution several times and maybe have wondered why is that. In this case, I wanted to build the project using two different configurations and also test and publish both. The thing is that if you execute MsBuild with the “Publish” flag enabled (so you can get the ClickOnce artifacts), MsBuild will only build the needed projects. Test projects, for instance, won’t be built at all. And that’s why I have to build the solution twice: the first build is aimed for testing purposes and the second one for publishing purposes.

4. Some errors you might find

During the creation of this script I faced two different problems:

My certificate was a .p12 file, not a .pfx

If that’s also your case, don’t worry. You can make it work easily:

  1. Install your .p12 on your machine.
  2. Click the Start button and type certmgr.msc
  3. Find your certificate, right click on it and select All Tasks > Export.
  4. Follow the wizard and select Yes when asked if you want to add the private key.
  5. In the security step, check the Password checkbox and enter one.
  6. Set the path of the resulting file, which will be a .pfx file.
  7. Use this .pfx in order to sign your project.
  8. Add this .pfx to your repository and you’re ready to go!

AssemblyVersion error

If you find this error and you don’t know what it is don’t worry because it has a very simple solution.

appveyor version error

Just go to Settings > General and check the “Build version format” that you’ve got there. If you have something like this (1.0.{build}), then you will have to change it.

appveyor version error input

Basically, you need a four digit version, i.e. 1.0.0.{build}.

Save the settings and that’s all! ;D

Hope it helps!

If you have any questions just let me know and I’ll be glad to explain what I did further if needed.