Skip to content

Commit 82ea015

Browse files
committed
Add launch script so contributors can F5 the VS extension without a matching-Roslyn VS
The F# VS extension compiles against Roslyn but binds at runtime to the Roslyn already in the running VS. main tracks a Roslyn ahead of public Stable/Insiders VS, so a clean-checkout build hard-binds to a Roslyn the contributor's VS lacks and F5 fails to load the extension. Previously the only options were an internal nightly VS or a local Roslyn build. Add start-vs-VisualFSharpSln.ps1 to launch VS building the extension against the Roslyn the installed VS ships, and point to it from DEVGUIDE. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8d0bf23d-fe1f-4874-b013-0358a431cc19
1 parent f8287a1 commit 82ea015

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

DEVGUIDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ First, ensure that `VisualFSharpDebug` is the startup project.
371371

372372
Then, use the **f5** or **ctrl+f5** keyboard shortcuts to test your tooling changes. The former will debug a new instance of Visual Studio. The latter will launch a new instance of Visual Studio, but with your changes installed.
373373

374+
> [!TIP]
375+
> If the F# extension fails to load when you F5 (because the Roslyn version in the repo is ahead of the one in your Visual Studio), launch VS with `.\start-vs-VisualFSharpSln.ps1` instead of opening the solution directly. It builds the extension against the Roslyn your VS actually ships, so you don't need an internal/nightly VS or a local Roslyn build. Requires VS with Roslyn 5.10 or newer.
376+
374377
Alternatively, you can do this entirely via the command line if you prefer that:
375378

376379
```shell

start-vs-VisualFSharpSln.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)