Add build tasks to the Visual Studio Code workspace file to enable building with MSBuild in VSCode.

This commit is contained in:
2025-08-03 19:01:50 -04:00
parent 66c29fdd34
commit b7b72e2129
4 changed files with 145 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
# Folder local settings are ignored.
# Settings that should be checked in should go in the workspace file.
.vscode/settings.json
# This is needed to make the build system machine-independent.
vswhere.exe

View File

@@ -0,0 +1,62 @@
##############################################################################
##
## Invoke-CmdScript
##
## From PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
## <https://powershellcookbook.com/recipe/WqHr/program-retain-changes-to-environment-variables-set-by-a-batch-file>
##
##############################################################################
<#
.SYNOPSIS
Invoke the specified batch file (and parameters), but also propagate any
environment variable changes back to the PowerShell environment that
called it.
.EXAMPLE
PS > type foo-that-sets-the-FOO-env-variable.cmd
@set FOO=%*
echo FOO set to %FOO%.
PS > $env:FOO
PS > Invoke-CmdScript "foo-that-sets-the-FOO-env-variable.cmd" Test
C:\Temp>echo FOO set to Test.
FOO set to Test.
PS > $env:FOO
Test
#>
param(
## The path to the script to run
[Parameter(Mandatory = $true)]
[string] $Path,
## The arguments to the script
[string] $ArgumentList
)
Set-StrictMode -Version 3
$tempFile = [IO.Path]::GetTempFileName()
## Store the output of cmd.exe. We also ask cmd.exe to output
## the environment table after the batch file completes
cmd /c " `"$Path`" $argumentList && set > `"$tempFile`" "
## Go through the environment variables in the temp file.
## For each of them, set the variable in our local environment.
Get-Content $tempFile | Foreach-Object {
if($_ -match "^(.*?)=(.*)$")
{
Set-Content "env:\$($matches[1])" $matches[2]
}
}
Remove-Item $tempFile

25
proj/vscode/build.ps1 Normal file
View File

@@ -0,0 +1,25 @@
Set-Location proj\vscode
$vswhere_path = "vswhere.exe"
if(-not(Test-Path -path $vswhere_path)) {
(New-Object Net.WebClient).DownloadFile('https://github.com/microsoft/vswhere/releases/latest/download/vswhere.exe', $vswhere_path)
if(-not(Test-Path -path $vswhere_path)) {
Write-Output 'Failed to download vswhere.exe'
exit 1
}
}
# $msbuild_path = .\proj\vscode\vswhere -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1
$vars_path = .\vswhere -latest -products * -requires Microsoft.Component.MSBuild -find **\VC\Auxiliary\Build\vcvars64.bat
if($vars_path) {
.\Invoke-CmdScript $vars_path
# Write-Output $msbuild_path @args
# & "$msbuild_path\..\..\..\..\VC\Auxiliary\Build\vcvars64.bat"
# Write-Output $env:PATH
MSBuild @args
} else {
Write-Output 'Could not find MSBuild.exe'
exit 1
}

View File

@@ -10,6 +10,62 @@
"ms-vscode.cpptools",
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "Build (Debug)",
"windows": {
"type": "process",
"command": "powershell",
"args": [
"${workspaceFolder}/proj/vscode/build.ps1",
"/property:GenerateFullPaths=true",
"/property:VcpkgConfiguration=Debug",
"/t:build",
"\"${workspaceRoot}\\proj\\vs2017\\Blades of Exile.sln\""
],
"problemMatcher": "$msCompile",
},
"group": "build"
},
{
"label": "Build (Release)",
"windows": {
"type": "process",
"command": "powershell",
"args": [
"${workspaceFolder}/proj/vscode/build.ps1",
"/property:GenerateFullPaths=true",
"/property:VcpkgConfiguration=Release",
"/t:build",
"${workspaceRoot}\\proj\\vs2013\\Blades of Exile.sln"
],
"problemMatcher": "$msCompile",
},
"group": "build"
},
{
"label": "Run tests",
"windows": {
"type": "process",
"command": "${workspaceRoot}\\proj\\vs2013\\Release\\OBoE Tests.exe",
"problemMatcher": {
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^\\.(.*)\\((\\d+)\\): FAILED$",
"file": 1,
"line": 2
}
},
},
"options": {
"cwd": "${workspaceRoot}/test"
},
"group": "test"
}
]
},
"settings": {
"xml.fileAssociations": [
{