Skip to content

Commit 2166170

Browse files
jimmylewisjayaranigarg
authored andcommitted
Fix build script to work with VS2019 (#641)
* Fix build script to work with VS2019 The main change is to try to find msbuild using the 'Current' version instead of the '15.0' version. The MSBuild team has stated that 'Current' will be used going forward to avoid a breaking change to the path when the version revs. Also necessary in this change was to drop the /toolsVersion flag from msbuild. It was passing 15.0 but that tools version is not recognized in the current MSBuild. Lastly, added the UWP.Support component as a required build component. When the build targets an instance of VS missing this feature, the build will fail when trying to find Microsoft.Windows.UI.Xaml.CSharp.Targets. * Handle when Resolve-Path throws if VS2019 is not present
1 parent 67c9f43 commit 2166170

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

scripts/Build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ function Invoke-Build([string] $solution, $hasVsixExtension = "false")
223223
$solutionFailureLog = Join-Path -path $solutionDir -childPath "msbuild.err"
224224

225225
Write-Log " Building $solution..."
226-
Write-Verbose "$msbuild /t:$Target /p:Configuration=$configuration /tv:$msbuildVersion /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath"
227-
& $msbuild /t:$Target /p:Configuration=$configuration /tv:$msbuildVersion /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath
226+
Write-Verbose "$msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath"
227+
& $msbuild /t:$Target /p:Configuration=$configuration /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath
228228

229229
if ($lastExitCode -ne 0) {
230230
throw "Build failed with an exit code of '$lastExitCode'."

scripts/common.lib.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,19 @@ function Locate-MSBuild($hasVsixExtension = "false") {
5454

5555
function Locate-MSBuildPath($hasVsixExtension = "false") {
5656
$vsInstallPath = Locate-VsInstallPath -hasVsixExtension $hasVsixExtension
57-
$msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\$msbuildVersion\Bin"
58-
return Resolve-Path -path $msbuildPath
57+
58+
# first try to find the VS2019+ path
59+
try {
60+
$msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\Current\Bin"
61+
$msbuildPath = Resolve-Path $msbuildPath
62+
}
63+
catch {
64+
# Resolve-Path throws if the path does not exist, so use the VS2017 path as a fallback
65+
$msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\$msbuildVersion\Bin"
66+
$msbuildPath = Resolve-Path $msbuildPath
67+
}
68+
69+
return $msbuildPath
5970
}
6071

6172
function Locate-NuGet {
@@ -117,6 +128,7 @@ function Locate-VsInstallPath($hasVsixExtension ="false"){
117128

118129
$requiredPackageIds += "Microsoft.Component.MSBuild"
119130
$requiredPackageIds += "Microsoft.Net.Component.4.6.TargetingPack"
131+
$requiredPackageIds += "Microsoft.VisualStudio.Windows.Build"
120132

121133
if($hasVsixExtension -eq 'true')
122134
{

0 commit comments

Comments
 (0)