Build installer using GitHub Actions

989 Views Asked by At

Is it possible to automate building the installer using GitHub Actions? This is a VSTO add-in solution containing several .NET projects and one "Visual Studio Installer Project" (a.k.a. vdproj). I need to build the installer project upon commit to a particular branch.

2

There are 2 best solutions below

0
On

Yes, it is possible.

First of all, make sure the environment is Windows:

jobs:
    ....
    runs-on: windows-2022

To build VSTO solution, you will have to import the pfx certificate first:

- name: Import certificate from the command-line
  shell: pwsh
  run: |
    $Secure_String_Pwd = ConvertTo-SecureString "<password>" -AsPlainText -Force
    Import-PfxCertificate -FilePath '${{github.workspace}}\<path>\project1_TemporaryKey.pfx' -CertStoreLocation Cert:\CurrentUser\My -Password $Secure_String_Pwd
    

Then build the VSTO using msbuild:

- name: setup-msbuild
  uses: microsoft/[email protected]

- name: Set VS.net environment
  run: cmd.exe /C CALL "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
- name: Build VSTO
  run: msbuild ${{github.workspace}}\yourproject.sln -t:rebuild /p:Platform="Any CPU" /p:Configuration="Release" /nologo /nr:false /p:VisualStudioVersion="17.0"

And build the Visual studio installer project:

- name: Setup VS Dev Environment
  uses: seanmiddleditch/gha-setup-vsdevenv@v4
- name: Build installer
  run: devenv.com ${{github.workspace}}\yourproject\yourproject.vdproj /build "Release|Any CPU"
0
On

If you are running this on a VS2019 build

jobs:
  build:
    runs-on: windows-2019

you may need to apply the registry hack that addresses the error

------ Starting pre-build validation for project 'YourInstaller' ------ 
ERROR: An error occurred while validating.  HRESULT = '8000000A'

Thanks to the information provided in this link Building VDProj I have copied the suggested Powershell script into a github action to fix the registry for the version of Visual Studio being used.

The script just adds a Registry entry in the correct location for the version of Visual Studio in use and sets a registry entry EnableOutOfProcBuild to 0.

  - name: DisableOutOfProc Fix
    run: |
      function Invoke-DisableOutOfProcBuild {
        param ();
        $visualStudioWherePath = ('{0}/Microsoft Visual Studio/Installer/vswhere.exe' -f ${Env:ProgramFiles(x86)});
        $visualStudioInstallationPath = & $visualStudioWherePath -latest -products 'Microsoft.VisualStudio.Product.Enterprise' -property 'installationPath';
        $currentWorkingDirectory = ('{0}/Common7/IDE/CommonExtensions/Microsoft/VSI/DisableOutOfProcBuild' -f $visualStudioInstallationPath);
        
        Set-Location -Path $currentWorkingDirectory;
        
        $disableOutOfProcBuildPath = ('{0}/DisableOutOfProcBuild.exe' -f $currentWorkingDirectory);
        
        & $disableOutOfProcBuildPath;
        
        return;
      }
      Invoke-DisableOutOfProcBuild