diff --git a/Build/build-functions.psm1 b/Build/build-functions.psm1 index bf777a7b73..c3f9a68f14 100644 --- a/Build/build-functions.psm1 +++ b/Build/build-functions.psm1 @@ -8,10 +8,17 @@ $toolsDir = "$root\.tools" $nuget = "$toolsDir\NuGet.exe" $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -$msbuildPath = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath -if ($msbuildPath) { - $msbuildx64 = join-path $msbuildPath 'MSBuild\Current\Bin\amd64\MSBuild.exe' +# Check if Visual Studio is installed before trying to find MSBuild +if (Test-Path $vswhere) { + $msbuildPath = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath 2>$null + + if ($msbuildPath) { + $msbuildx64 = join-path $msbuildPath 'MSBuild\Current\Bin\amd64\MSBuild.exe' + } +} else { + $msbuildPath = $null + $msbuildx64 = $null } import-module $PSScriptRoot\build-pack-nano-nugets.psm1 @@ -45,15 +52,22 @@ function Start-Build([boolean] $IncludeNanoFramework = $false) { } else { - write-host -foreground green "Build .NET nanoFramework." - $fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.NanoFramework.msbuild.log" - - # msbuild does not auto-restore nugets for this project type - & "$nuget" restore "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" - - # now build - & "$msbuildx64" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release /p:Platform="Any CPU" /p:ContinuousIntegrationBuild=true $fileLoggerArg - if ($lastexitcode -ne 0) { exit 1 } + # Check if MSBuild is available before attempting NanoFramework build + if (-not $msbuildx64 -or -not (Test-Path $msbuildx64)) { + write-host -foreground yellow "Cannot build .NET nanoFramework - MSBuild not found. Install Visual Studio to build NanoFramework projects." + write-host -foreground yellow "Continuing with main build only..." + } + else { + write-host -foreground green "Build .NET nanoFramework." + $fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.NanoFramework.msbuild.log" + + # msbuild does not auto-restore nugets for this project type + & "$nuget" restore "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" + + # now build + & "$msbuildx64" "$root\UnitsNet.NanoFramework\GeneratedCode\UnitsNet.nanoFramework.sln" /verbosity:minimal /p:Configuration=Release /p:Platform="Any CPU" /p:ContinuousIntegrationBuild=true $fileLoggerArg + if ($lastexitcode -ne 0) { exit 1 } + } } write-host -foreground blue "Start-Build...END`n" diff --git a/Build/init.ps1 b/Build/init.ps1 index bed427b0dd..bb3478bf63 100644 --- a/Build/init.ps1 +++ b/Build/init.ps1 @@ -27,8 +27,23 @@ if (-not (Test-Path "$nugetPath")) { ################################################### ## TODO: OK to remove after moving to AZDO pipeline $VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe" -$VsPath = $(&$VsWherePath -latest -property installationPath) -$msbuildPath = Join-Path -Path $VsPath -ChildPath "\MSBuild" + +# Check if Visual Studio is installed +if (Test-Path $VsWherePath) { + $VsPath = $(&$VsWherePath -latest -property installationPath 2>$null) + if ($VsPath) { + $msbuildPath = Join-Path -Path $VsPath -ChildPath "\MSBuild" + Write-Host -Foreground Green "Visual Studio found at: $VsPath" + } else { + Write-Host -Foreground Yellow "Visual Studio not found via vswhere, NanoFramework builds will be skipped" + $VsPath = $null + $msbuildPath = $null + } +} else { + Write-Host -Foreground Yellow "Visual Studio not installed - NanoFramework builds will be skipped" + $VsPath = $null + $msbuildPath = $null +} # Install dotnet CLI tools declared in /.config/dotnet-tools.json pushd $root @@ -36,7 +51,7 @@ dotnet tool restore popd # Install .NET nanoFramework build components -if (!(Test-Path "$msbuildPath/nanoFramework")) { +if ($msbuildPath -and !(Test-Path "$msbuildPath/nanoFramework")) { Write-Host "Installing .NET nanoFramework VS extension..." [System.Net.WebClient]$webClient = New-Object System.Net.WebClient @@ -60,7 +75,7 @@ if (!(Test-Path "$msbuildPath/nanoFramework")) { Write-Output "VsWherePath is: $VsWherePath" - $VsInstance = $(&$VSWherePath -latest -property displayName) + $VsInstance = $(&$VSWherePath -latest -property displayName 2>$null) Write-Output "Latest VS is: $VsInstance"