How to get .msi from powershell?

264 Views Asked by At

I'm trying to write a PowerShell script for Bamboo that will:

  • Build the installer to create an msi
  • Find all Unit Test projects (any .csproj files that end in 'UnitTests') and compile them.

After a bit of searching, I found that I can call $env:RestoreUseSkipNonexistentTargets='false' to finally get NuGet packages restored, and now things are building... except the installer msi. It gives this output:

Microsoft Visual Studio 2019 Version 16.8.2.
Copyright (C) Microsoft Corp. All rights reserved.

The license for Visual Studio expires in 29 days.

Some errors occurred during migration. For more information, see the migration report:
C:\Program Files\Atlassian\Application Data\bamboo-home\xml-data\build-dir\CD-VX10-JOB1\UpgradeLog.htm
1>------ Rebuild All started: Project: Core, Configuration: Release Any CPU ------
2>------ Rebuild All started: Project: Repositories, Configuration: Release Any CPU ------
3>------ Rebuild All started: Project: Services, Configuration: Release Any CPU ------
4>------ Rebuild All started: Project: VX10Desktop, Configuration: Release x86 ------
========== Rebuild All: 4 succeeded, 0 failed, 0 skipped ==========

Looking at the log as advised, it shows the following error:

Installer\Installer.vdproj: The application which this project type is based on was not found. Please try this link for further information: https://go.microsoft.com/fwlink/?LinkId=660952&projecttype=54435603-DBB4-11D2-8724-00A0C9A8B90C

Here's my script:

#Constants:
$devEnv = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv"

#External Variables:
$nuget = $env:nuget

function Main {
    $ErrorActionPreference = "Stop"
    $sln = Get-SolutionFile
    
    Restore-NugetPackages $sln
    Compile-DesktopProject $sln

    exit $LASTEXITCODE
}

function Compile-DesktopProject($slnFile) {
    $projectFile = Get-ChildItem "*.vdproj" -Recurse
    $filePath = $projectFile.FullName
    Run-Cmd("& `'$devEnv' /Rebuild Release '$slnFile'")#Build everything but vdproj
    Run-Cmd("& `'$devEnv' /Rebuild Release '$slnFile' /Project '$filePath'")#Build vdproj - NOT WORKING
}

function Get-SolutionFile {
    $files = ls *.sln
    if($files.Count -ne 1){
        echo 'Expected exactly one .sln file.'
        exit 1 
    }
    $file = $files[0]
    return $file
}

function Restore-NugetPackages($slnFile) {
    $env:RestoreUseSkipNonexistentTargets='false'
    Run-Cmd("& `'$($nuget)' restore '$($slnFile)'")
}

function Run-Cmd($cmd){
    write-host "Running: $cmd"
    Invoke-Expression $cmd
}

Main

Why is my .msi not building and how can I make this work?


Worth noting: When, on my local machine, I restore NuGet packages in Visual Studio and then run my DevEnv, it works and the msi is created. It's only when I run the PowerShell script on the Bamboo server that that the msi isn't created. So maybe it has something to do with the server/DevEnv installation?

0

There are 0 best solutions below