|
| 1 | +# Launch VS on VisualFSharp.slnx, building the F# VS extension against the Roslyn your installed VS |
| 2 | +# ships (not the newer one flowed into the repo) so F5 loads it. See DEVGUIDE.md. Needs VS Roslyn >= 5.10. |
| 3 | +# -RoslynVersion forces a version (e.g. if the exact VS build isn't on a feed); any 5.Y.* binds identically. |
| 4 | +[CmdletBinding()] |
| 5 | +param( |
| 6 | + [string]$RoslynVersion, |
| 7 | + [string]$DevEnv, |
| 8 | + [string]$Solution = 'VisualFSharp.slnx', |
| 9 | + [switch]$DryRun |
| 10 | +) |
| 11 | +Set-StrictMode -Version Latest; $ErrorActionPreference = 'Stop'; $root = $PSScriptRoot |
| 12 | + |
| 13 | +if (-not $DevEnv) { |
| 14 | + $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' |
| 15 | + $DevEnv = if ($env:DevEnvDir) { Join-Path $env:DevEnvDir 'devenv.exe' } |
| 16 | + elseif (Test-Path $vswhere) { & $vswhere -latest -prerelease -property productPath 2>$null } |
| 17 | +} |
| 18 | +if (-not ($DevEnv -and (Test-Path $DevEnv))) { throw 'devenv.exe not found; run from a VS Developer prompt or pass -DevEnv.' } |
| 19 | + |
| 20 | +if (-not $RoslynVersion) { |
| 21 | + $dll = "$(Split-Path $DevEnv)\CommonExtensions\Microsoft\VBCSharp\LanguageServices\Microsoft.CodeAnalysis.dll" |
| 22 | + if (-not (Test-Path $dll)) { throw "Can't detect your VS Roslyn version; pass -RoslynVersion." } |
| 23 | + $RoslynVersion = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($dll).ProductVersion -split '\+')[0] |
| 24 | +} |
| 25 | +$minor = [version](($RoslynVersion -split '-')[0]) |
| 26 | +if ($minor -lt [version]'5.10.0') { |
| 27 | + throw "Your VS ships Roslyn $RoslynVersion but the repo references packages from >= 5.10 (unified ExternalAccess, #20099). Update VS or deploy a local Roslyn." |
| 28 | +} |
| 29 | +Write-Host "Building the F# extension against Roslyn $RoslynVersion ($DevEnv)." |
| 30 | + |
| 31 | +# Repoint every Roslyn package (versions set in eng/Version.Details.props) via a props file MSBuild |
| 32 | +# imports after it through the CustomAfterMicrosoftCommonProps hook the launched VS inherits. |
| 33 | +$names = 'MicrosoftCodeAnalysis', 'MicrosoftCodeAnalysisCompilers', 'MicrosoftCodeAnalysisCSharp', |
| 34 | + 'MicrosoftCodeAnalysisEditorFeatures', 'MicrosoftCodeAnalysisEditorFeaturesText', 'MicrosoftCodeAnalysisFeatures', |
| 35 | + 'MicrosoftVisualStudioLanguageServices', 'MicrosoftVisualStudioLanguageServicesExternalAccess' |
| 36 | +$override = Join-Path $root 'artifacts\RoslynOverride.props' |
| 37 | +New-Item -ItemType Directory -Force (Split-Path $override) | Out-Null |
| 38 | +"<Project><PropertyGroup>$(-join ($names | ForEach-Object { "<${_}Version>$RoslynVersion</${_}Version>" }))</PropertyGroup></Project>" | |
| 39 | + Set-Content -LiteralPath $override -Encoding UTF8 |
| 40 | + |
| 41 | +# Apply to THIS process only, restoring in finally so it can't leak into a later build.cmd/CI run |
| 42 | +# (which must keep the flowed Roslyn); the launched VS snapshots the env for its F5/restore builds. |
| 43 | +$vars = @{ |
| 44 | + CustomAfterMicrosoftCommonProps = $override |
| 45 | + DOTNET_ROOT = Join-Path $root '.dotnet' |
| 46 | + 'DOTNET_ROOT(x86)' = Join-Path $root '.dotnet\x86' |
| 47 | + PATH = "$(Join-Path $root '.dotnet');$env:PATH" |
| 48 | + RunNetFrameworkApiCompat = 'false' |
| 49 | + RunRefApiCompat = 'false' |
| 50 | +} |
| 51 | +$saved = @{}; foreach ($k in $vars.Keys) { $saved[$k] = [Environment]::GetEnvironmentVariable($k) } |
| 52 | +try { |
| 53 | + foreach ($k in $vars.Keys) { Set-Item -LiteralPath "Env:\$k" -Value $vars[$k] } |
| 54 | + if ($DryRun) { Write-Host "DryRun: $override"; return } |
| 55 | + & (Join-Path $root 'Restore.cmd') |
| 56 | + if ($LASTEXITCODE) { throw "Restore failed for Roslyn $RoslynVersion; try another 5.$($minor.Minor).* build via -RoslynVersion." } |
| 57 | + Start-Process $DevEnv "`"$(Join-Path $root $Solution)`"" |
| 58 | + Write-Host 'Launched VS. Set VisualFSharpDebug as the startup project, then F5 / Ctrl+F5.' |
| 59 | +} |
| 60 | +finally { |
| 61 | + foreach ($k in $saved.Keys) { |
| 62 | + if ($null -eq $saved[$k]) { Remove-Item -LiteralPath "Env:\$k" -ErrorAction SilentlyContinue } else { Set-Item -LiteralPath "Env:\$k" -Value $saved[$k] } |
| 63 | + } |
| 64 | +} |
0 commit comments