Skip to content

Commit fdca3e4

Browse files
committed
Add BuildIfChanged Task and Dev Instructions
1 parent fec1f3a commit fdca3e4

File tree

2 files changed

+57
-38
lines changed

2 files changed

+57
-38
lines changed

PowerShellEditorServices.build.ps1

+44-25
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,20 @@ task RestorePsesModules -If (-not (Test-Path "module/PSReadLine") -or -not (Test
125125
}
126126

127127
Task Build FindDotNet, CreateBuildInfo, RestorePsesModules, {
128-
Write-Build DarkGreen "Building PowerShellEditorServices"
128+
Write-Build DarkGreen 'Building PowerShellEditorServices'
129129
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices/PowerShellEditorServices.csproj -f $script:NetFramework.Standard }
130130
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS74 }
131131

132132
if (-not $script:IsNix) {
133133
Invoke-BuildExec { & dotnet publish $script:dotnetBuildArgs ./src/PowerShellEditorServices.Hosting/PowerShellEditorServices.Hosting.csproj -f $script:NetFramework.PS51 }
134134
}
135+
} -If {
136+
$Null -eq $script:ChangesDetected -or $true -eq $script:ChangesDetected
135137
}
136138

137139
Task AssembleModule -After Build {
138-
Write-Build DarkGreen "Assembling PowerShellEditorServices module"
139-
$psesOutputPath = "./module/PowerShellEditorServices"
140+
Write-Build DarkGreen 'Assembling PowerShellEditorServices module'
141+
$psesOutputPath = './module/PowerShellEditorServices'
140142
$psesBinOutputPath = "$psesOutputPath/bin"
141143
$psesDepsPath = "$psesBinOutputPath/Common"
142144
$psesCoreHostPath = "$psesBinOutputPath/Core"
@@ -147,8 +149,8 @@ Task AssembleModule -After Build {
147149
}
148150

149151
# Copy documents to module root
150-
foreach ($document in @("LICENSE", "NOTICE.txt", "README.md", "SECURITY.md")) {
151-
Copy-Item -Force -Path $document -Destination "./module"
152+
foreach ($document in @('LICENSE', 'NOTICE.txt', 'README.md', 'SECURITY.md')) {
153+
Copy-Item -Force -Path $document -Destination './module'
152154
}
153155

154156
# Assemble PSES module
@@ -186,13 +188,13 @@ Task AssembleModule -After Build {
186188
}
187189

188190
Task BuildCmdletHelp -After AssembleModule {
189-
Write-Build DarkGreen "Building cmdlet help"
191+
Write-Build DarkGreen 'Building cmdlet help'
190192
New-ExternalHelp -Path ./module/docs -OutputPath ./module/PowerShellEditorServices/Commands/en-US -Force
191193
}
192194

193195
Task SetupHelpForTests {
194-
Write-Build DarkMagenta "Updating help (for tests)"
195-
Update-Help -Module Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
196+
Write-Build DarkMagenta 'Updating help (for tests)'
197+
Update-Help -Module Microsoft.PowerShell.Management, Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
196198
}
197199

198200
Task TestPS74 Build, SetupHelpForTests, {
@@ -210,7 +212,7 @@ Task TestPS51 -If (-not $script:IsNix) Build, SetupHelpForTests, {
210212
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
211213
# Inheriting the module path for powershell.exe breaks things!
212214
$originalModulePath = $env:PSModulePath
213-
$env:PSModulePath = ""
215+
$env:PSModulePath = ''
214216
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS51 }
215217
} finally {
216218
$env:PSModulePath = $originalModulePath
@@ -221,7 +223,7 @@ Task TestPS51 -If (-not $script:IsNix) Build, SetupHelpForTests, {
221223
# should just be the latest supported framework.
222224
Task TestE2EPwsh Build, SetupHelpForTests, {
223225
Set-Location ./test/PowerShellEditorServices.Test.E2E/
224-
$env:PWSH_EXE_NAME = "pwsh"
226+
$env:PWSH_EXE_NAME = 'pwsh'
225227
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
226228
}
227229

@@ -240,12 +242,12 @@ Task TestE2EDaily -If (Test-Path $PwshDaily) Build, SetupHelpForTests, {
240242

241243
Task TestE2EPowerShell -If (-not $script:IsNix) Build, SetupHelpForTests, {
242244
Set-Location ./test/PowerShellEditorServices.Test.E2E/
243-
$env:PWSH_EXE_NAME = "powershell"
245+
$env:PWSH_EXE_NAME = 'powershell'
244246
try {
245247
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
246248
# Inheriting the module path for powershell.exe breaks things!
247249
$originalModulePath = $env:PSModulePath
248-
$env:PSModulePath = ""
250+
$env:PSModulePath = ''
249251
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
250252
} finally {
251253
$env:PSModulePath = $originalModulePath
@@ -254,45 +256,62 @@ Task TestE2EPowerShell -If (-not $script:IsNix) Build, SetupHelpForTests, {
254256

255257
Task TestE2EPwshCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
256258
Set-Location ./test/PowerShellEditorServices.Test.E2E/
257-
$env:PWSH_EXE_NAME = "pwsh"
259+
$env:PWSH_EXE_NAME = 'pwsh'
258260

259-
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
260-
Write-Build DarkRed "Skipping Constrained Language Mode tests as they must be ran in an elevated process"
261+
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown('BuiltInAdministratorsSid')) {
262+
Write-Build DarkRed 'Skipping Constrained Language Mode tests as they must be ran in an elevated process'
261263
return
262264
}
263265

264266
try {
265-
Write-Build DarkGreen "Running end-to-end tests in Constrained Language Mode"
266-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
267+
Write-Build DarkGreen 'Running end-to-end tests in Constrained Language Mode'
268+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', '0x80000007', [System.EnvironmentVariableTarget]::Machine)
267269
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
268270
} finally {
269-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
271+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', $null, [System.EnvironmentVariableTarget]::Machine)
270272
}
271273
}
272274

273275
Task TestE2EPowerShellCLM -If (-not $script:IsNix) Build, SetupHelpForTests, {
274276
Set-Location ./test/PowerShellEditorServices.Test.E2E/
275-
$env:PWSH_EXE_NAME = "powershell"
277+
$env:PWSH_EXE_NAME = 'powershell'
276278

277-
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
278-
Write-Build DarkRed "Skipping Constrained Language Mode tests as they must be ran in an elevated process"
279+
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown('BuiltInAdministratorsSid')) {
280+
Write-Build DarkRed 'Skipping Constrained Language Mode tests as they must be ran in an elevated process'
279281
return
280282
}
281283

282284
try {
283-
Write-Build DarkGreen "Running end-to-end tests in Constrained Language Mode"
284-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine)
285+
Write-Build DarkGreen 'Running end-to-end tests in Constrained Language Mode'
286+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', '0x80000007', [System.EnvironmentVariableTarget]::Machine)
285287
# TODO: See https://github.com/PowerShell/vscode-powershell/issues/3886
286288
# Inheriting the module path for powershell.exe breaks things!
287289
$originalModulePath = $env:PSModulePath
288-
$env:PSModulePath = ""
290+
$env:PSModulePath = ''
289291
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
290292
} finally {
291-
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine)
293+
[System.Environment]::SetEnvironmentVariable('__PSLockdownPolicy', $null, [System.EnvironmentVariableTarget]::Machine)
292294
$env:PSModulePath = $originalModulePath
293295
}
294296
}
295297

298+
Task BuildIfChanged.Init -Before BuildIfChanged {
299+
[bool]$script:ChangesDetected = $false
300+
}
301+
302+
Task BuildIfChanged -Inputs {
303+
$slash = [IO.Path]::DirectorySeparatorChar
304+
Get-ChildItem ./src -Filter '*.cs' -Recurse
305+
| Where-Object FullName -NotLike ('*' + $slash + 'obj' + $slash + '*')
306+
| Where-Object FullName -NotLike ('*' + $slash + 'bin' + $slash + '*')
307+
} -Outputs {
308+
'./src/PowerShellEditorServices/bin/Debug/netstandard2.0/Microsoft.PowerShell.EditorServices.dll'
309+
'./src/PowerShellEditorServices.Hosting/bin/Debug/net8.0/Microsoft.PowerShell.EditorServices.Hosting.dll'
310+
} -Jobs {
311+
Write-Build DarkMagenta 'Changes detected, rebuilding'
312+
$script:ChangesDetected = $true
313+
}, Build
314+
296315
Task Test TestPS74, TestE2EPwsh, TestPS51, TestE2EPowerShell
297316

298317
Task TestFull Test, TestE2EDaily, TestE2EPwshCLM, TestE2EPowerShellCLM

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Please note that we only consider the following as stable APIs that can be relie
153153

154154
The types of PowerShell Editor Services can change at any moment and should not be linked against in a production environment.
155155

156-
## Development
156+
## Development Environment
157157

158158
> [!TIP]
159159
> The easiest way to manually test changes you've made in PowerShellEditorServices is to follow the [vscode-powershell development doc](https://github.com/PowerShell/vscode-powershell/blob/main/docs/development.md).
@@ -175,31 +175,31 @@ Install-Module InvokeBuild -Scope CurrentUser
175175
Install-Module platyPS -Scope CurrentUser
176176
```
177177

178-
### 4. Delete `NuGet.Config`
178+
### 4. Adjust `nuget.config` if necessary
179179

180-
Our NuGet configuration points to a private feed necessary for secure builds,
181-
and it must be committed to the repo as it is.
182-
The easiest way to build without access to that private feed is to delete the file:
180+
Our NuGet configuration uses a secure feed with allow-listed third party dependency packages. If your contribution requires any changes to the included NuGet packages, you must disable this secure feed.
181+
182+
First, run this command to prevent accidentally commiting changes to this file
183183

184184
```powershell
185-
Remove-Item NuGet.Config
185+
git update-index --skip-worktree nuget.config
186186
```
187187

188-
Please be careful not to commit this change in a PR.
188+
Then, either delete the file or remove the `packagesources` section to use nuget.org again. Your PR _will_ fail automated build checks and you _must_ inform us at the top of your PR so the appropriate packages can be added if approved.
189189

190-
Now you're ready to build the code.
191-
You can do so in one of two ways:
190+
## Build PowerShell Editor Services
191+
Now you're ready to build the code. You can do so in one of two ways:
192192

193-
### Building the code from PowerShell
193+
### PowerShell
194194

195195
```powershell
196-
PS C:\path\to\PowerShellEditorServices> Invoke-Build Build
196+
PS C:\src\PowerShellEditorServices> Invoke-Build
197197
```
198198

199-
### Building the code from Visual Studio Code
199+
### Visual Studio Code
200200

201201
Open the PowerShellEditorServices folder that you cloned locally and press <kbd>Ctrl+Shift+B</kbd>
202-
(or <kbd>Cmd+Shift+B</kbd> on macOS).
202+
(or <kbd>Cmd+Shift+B</kbd> on macOS) which will run the default build task.
203203

204204
## Code of Conduct
205205

0 commit comments

Comments
 (0)