Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions Build/build-functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
23 changes: 19 additions & 4 deletions Build/init.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,31 @@ 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
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
Expand All @@ -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"

Expand Down
Loading