<# .SYNOPSIS Rebuilds the ClickOnce installer for BulkArchiveMailer.AddIn (Способ А in ../docs/BUILD.md) without hand-typing the long MSBuild -t:Publish command each time. .DESCRIPTION Wraps: MSBuild.exe BulkArchiveMailer.AddIn\BulkArchiveMailer.AddIn.csproj -t:Publish -p:Configuration=Release -p:PublishUrl=\BulkArchiveMailer.AddIn\bin\Release\app.publish\ -p:InstallUrl=\BulkArchiveMailer.AddIn\bin\Release\app.publish\ -p:PublishDir=bin\Release\app.publish\ -p:UpdateEnabled=false MSBuild.exe is located via vswhere.exe first (works across VS installs/versions/editions); if vswhere itself isn't found, falls back to the fixed path this repo has been built with so far (D:\VS2022\MSBuild\Current\Bin\amd64\MSBuild.exe). Pass -MSBuildPath to override either lookup explicitly. .PARAMETER MSBuildPath Explicit path to MSBuild.exe. Skips both the vswhere lookup and the hardcoded fallback when supplied. .EXAMPLE .\deploy\publish-clickonce.ps1 .EXAMPLE .\deploy\publish-clickonce.ps1 -MSBuildPath 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe' #> [CmdletBinding()] param( [string]$MSBuildPath ) $ErrorActionPreference = 'Stop' # Repo layout: this script lives in outlook-bulk-sender\deploy\, the # project lives one level up in outlook-bulk-sender\BulkArchiveMailer.AddIn\. $repoRoot = Split-Path -Parent $PSScriptRoot $projectPath = Join-Path $repoRoot 'BulkArchiveMailer.AddIn\BulkArchiveMailer.AddIn.csproj' $publishDir = Join-Path $repoRoot 'BulkArchiveMailer.AddIn\bin\Release\app.publish\' if (-not (Test-Path $projectPath)) { throw "Project file not found: $projectPath" } function Resolve-MSBuildPath { param([string]$explicitPath) if ($explicitPath) { if (-not (Test-Path $explicitPath)) { throw "-MSBuildPath was given but does not exist: $explicitPath" } return $explicitPath } $vswhere = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' if (Test-Path $vswhere) { $found = & $vswhere -latest -requires Microsoft.Component.MSBuild -find 'MSBuild\**\Bin\MSBuild.exe' 2>$null | Select-Object -First 1 if ($found -and (Test-Path $found)) { Write-Host "Using MSBuild found via vswhere: $found" return $found } Write-Warning 'vswhere.exe ran but did not report a usable MSBuild.exe - falling back to the fixed path.' } else { Write-Warning "vswhere.exe not found at '$vswhere' - falling back to the fixed path." } $fallback = 'D:\VS2022\MSBuild\Current\Bin\amd64\MSBuild.exe' if (-not (Test-Path $fallback)) { throw "Could not locate MSBuild.exe via vswhere, and the fallback path does not exist either: $fallback. Pass -MSBuildPath explicitly." } Write-Host "Using fallback MSBuild path: $fallback" return $fallback } $msbuild = Resolve-MSBuildPath -explicitPath $MSBuildPath Write-Host "Publishing $projectPath (Release, local ClickOnce, updates disabled) to:`n $publishDir" & $msbuild $projectPath ` -t:Publish ` -p:Configuration=Release ` -p:PublishUrl=$publishDir ` -p:InstallUrl=$publishDir ` -p:PublishDir=$publishDir ` -p:UpdateEnabled=false ` -m if ($LASTEXITCODE -ne 0) { throw "MSBuild -t:Publish failed with exit code $LASTEXITCODE" } $vstoPath = Join-Path $publishDir 'BulkArchiveMailer.AddIn.vsto' if (Test-Path $vstoPath) { Write-Host "`nDone. Installer manifest: $vstoPath" Write-Host "Copy the whole 'app.publish' folder to the operator's machine and double-click the .vsto file there (see docs/BUILD.md, Способ А)." } else { Write-Warning "Publish reported success but $vstoPath was not found - check the MSBuild output above." }