Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cacde42
Modernize Dev Container Configuration for PowerShell Development
JustinGrote May 9, 2025
129db4e
Further Devcontainer Updates
JustinGrote May 10, 2025
59286fb
Add debug symbolic link to enable easy access to published image
JustinGrote May 10, 2025
0916b2b
Remove PrelaunchTask requirement for debug
JustinGrote May 10, 2025
6e24c4b
Add debug symlink to poststart
JustinGrote May 12, 2025
6e3f10a
Convert to Dockerfile based devcontainer to embed startup scripts
JustinGrote May 16, 2025
b3e68d3
Supress progress cluttering the codespaces prebuild logs
JustinGrote May 16, 2025
d577ec3
Revise tasks to use the shell at the default pwsh path (to allow cust…
JustinGrote May 16, 2025
4583361
More terminal fixes
JustinGrote May 16, 2025
1bb7e39
Fix debug pwsh to use absolute path
JustinGrote May 16, 2025
b5e94bf
Update default formatters for various languages
JustinGrote May 16, 2025
b1211f1
Remove typo
JustinGrote May 16, 2025
d5db1e7
Add back workspacemount to account for codespaces
JustinGrote May 16, 2025
1624058
Build: Add `-PublishLinkPath` to `Start-PSBuild`
JustinGrote May 17, 2025
dcc1fdd
Better symbolic linking to deal with named volumes etc.
JustinGrote May 17, 2025
37e354e
Fix target and swallow output object
JustinGrote May 17, 2025
9672ec7
Use relative path for debug
JustinGrote May 17, 2025
2ecffef
Absolute path to symlinked terminal
JustinGrote May 17, 2025
f9f777c
Suppress moduleload and exceptions in PowerShell Dev Console Launch C…
JustinGrote May 17, 2025
f16e7d5
Update extensions
JustinGrote May 17, 2025
8e0068f
Remove "JG" prefix
JustinGrote May 17, 2025
bd407bd
Change name to "PowerShell Dev"
JustinGrote May 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions 28 .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
ARG VARIANT=preview
FROM mcr.microsoft.com/devcontainers/dotnet:${VARIANT}

FROM mcr.microsoft.com/powershell/test-deps:ubuntu-20.04@sha256:d1609c57d2426b9cfffa3a3ab7bda5ebc4448700f8ba8ef377692c4a70e64b8c

# Avoid warnings by switching to noninteractive
ENV DEBIAN_FRONTEND=noninteractive

# Configure apt and install packages
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install --no-install-recommends apt-utils 2>&1 \
#
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
&& apt-get -y install --no-install-recommends git procps lsb-release \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=dialog
# This is a workaround for https://github.com/microsoft/vscode-remote-release/issues/10934
ADD ./scripts /devcontainer/scripts
97 changes: 87 additions & 10 deletions 97 .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,99 @@
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/dotnet
{
"name": ".NET Core 6.0, including pwsh (Ubuntu 18.04)",
"dockerFile": "Dockerfile",
"name": "PowerShell Dev",
"build": {
"dockerfile": "Dockerfile",
"args": {
// NOTE: This should be kept up to date to match the .NET SDK currently in use on the master branch.
// but not mandatory as we fetch the appropriate .NET SDK as needed during build.
// See: https://mcr.microsoft.com/en-us/artifact/mar/devcontainers/dotnet/tags for available tags.
"VARIANT": "1-10.0-preview-noble"
}
},
"hostRequirements": {
"cpus": 4 // .NET compliation is intensive so we want more cores by default
},
"capAdd": [
"NET_RAW" // Needed for Pester tests that require ping
],

// This path is symlinked in the onCreateCommand to the actual workspaceFolder
// We use it for convenience and consistency with the settings that require absolute paths.
// NOTE: This is ignored when using a named volume devcontainer but will still work fine.
"remoteUser": "vscode",
"containerUser": "vscode",

// This is required if the dotnet is updated to a later version than what is in the image.
// So that the C# extension can detect it. Doing it in .bashrc is not enough.
"remoteEnv": {
"PATH": "/home/vscode/.dotnet:${containerEnv:PATH}"
},

"workspaceMount": "source=${localWorkspaceFolder},target=/PowerShell,type=bind",
"workspaceFolder": "/PowerShell",
// Container lifecycle scripts
// Docs: https://containers.dev/implementors/json_reference/#lifecycle-scripts

// Uncomment the next line to run commands after the container is created.
"postCreateCommand": "cd src/powershell-unix && dotnet restore",
// NOTE: We don't use initializeCommand because that runs on the host and we may not know what OS it is.
"onCreateCommand": [
"/usr/bin/pwsh",
"-nop",
"-noni",
"-f",
"/devcontainer/scripts/1-onCreate.ps1"
],
"updateContentCommand": [
"/usr/bin/pwsh",
"-nop",
"-noni",
"-f",
"/devcontainer/scripts/2-updateContent.ps1"
],

// These lifecycle scripts are non-blocking to loading the codespace and UI by default
"postCreateCommand": [
"/usr/bin/pwsh",
"-nop",
"-noni",
"-f",
"/devcontainer/scripts/3-postCreate.ps1"
],
"postStartCommand": [
"/usr/bin/pwsh",
"-nop",
"-noni",
"-f",
"/devcontainer/scripts/4-postStart.ps1"
],
// This runs in a vscode terminal after startup and is generally not needed but here for reference.
// "postAttachCommand": ["/usr/bin/pwsh", "-nop", "-noni", "-f", "/devcontainer/scripts/5-postAttach.ps1"],

// Configure tool-specific properties.
"customizations": {
"vscode": {
"settings": {
"dotnet.defaultSolution": "PowerShell.sln",
"dotnet.testWindow.useTestingPlatformProtocol": true,
"csharp.experimental.debug.hotReload": true,
"powershell.powerShellAdditionalExePaths": {
"PowerShell-Dev": "${workspaceFolder}/debug/pwsh"
},
"terminal.integrated.profiles.linux": {
"pwsh dev": {
"path": "/powershell/debug/pwsh",
"icon": "terminal-powershell",
"color": "terminal.ansiMagenta"
}
}
},
"extensions": [
"ms-azure-devops.azure-pipelines",
"ms-dotnettools.csharp",
"ms-vscode.powershell",
"ms-dotnettools.csdevkit",
"ms-vscode.PowerShell",
"GitHub.vscode-pull-request-github",
"ms-azure-devops.azure-pipelines",
"editorconfig.editorconfig",
"DavidAnson.vscode-markdownlint",
"vitaliymaz.vscode-svg-previewer"
"esbenp.prettier-vscode"
]
}
}
Expand Down
31 changes: 31 additions & 0 deletions 31 .devcontainer/scripts/1-onCreate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#Docs: https://containers.dev/implementors/json_reference/#lifecycle-scripts
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'

# The workspace folder name can be variable, we need a stable target for some settings like terminal path
$absolutePath = '/powershell'
. $PSScriptRoot/shared.ps1

if ($PWD -ne $absolutePath) {
log "Linking $SCRIPT:WorkspaceFolder to $absolutePath"
sudo ln -s $SCRIPT:WorkspaceFolder /powershell
log "Adding $absolutePath to git safe directories"
git config --global --add safe.directory $absolutePath
}

log "Adding $SCRIPT:WorkspaceFolder to git safe directories"
git config --global --add safe.directory $SCRIPT:WorkspaceFolder


# NOTE: We override the Azure Devops private feed as it may not be up to date with the required packages
# This is only for development and not builds so any potential vulnerabilities will be caught at CI time
# If you want to restore private restore behavior for testing, perform the following:
# PS> dotnet nuget disable source nuget.org;dotnet nuget enable source powershell

#Because several PowerSHell build steps request you to use -UseNugetOrg, these files get changed when you do that. We ignore this in the codespaces so they do not get accidentally committed to PRs. You can always use --no-skip-worktree after build if you intentionally want to modify these files.
log 'Ignoring nuget.config changes'
git update-index --skip-worktree nuget.config src/Modules/nuget.config test/tools/Modules/nuget.config

log 'Switching to Nuget.Org Packages Only for Codespaces Development'
Import-Module ./build.psm1
Switch-PSNugetConfig -Source NuGetOnly
40 changes: 40 additions & 0 deletions 40 .devcontainer/scripts/2-updateContent.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#Docs: https://containers.dev/implementors/json_reference/#lifecycle-scripts
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'

. $PSScriptRoot/shared.ps1
Import-Module -Force ./build.psm1

#If doing a clone into devcontainer, VSCode defaults to a shallow clone. The build process does not support shallow
#clones due to the use of git tag describe, so we must "unshallow" it if this occurs
if ((git rev-parse --is-shallow-repository) -ne 'false') {
log 'Shallow Clone detected, this is not supported by the PowerShell build process. Unshallowing...'
git fetch --unshallow
}

# Fetch upstream tags. The PowerShell dotnet restore requires this (GetPSCoreVersionFromGit)
log 'Syncing PowerShell Git Tags from Remote'
Sync-PSTags -AddRemoteIfMissing

log 'Bootstrap PowerShell Build Prerequisites'

Start-PSBootstrap -Scenario DotNet

#Ping is needed for tests but is not included in the .NET SDK devcontainer and PSBootstrap doesn't cover it
log 'Installing iputils (for the ping utility)'
sudo apt install iputils-ping -y

# Perform an initial build of PowerShell, this is needed so the "pwsh dev" terminal and debug launch tasks are available on first run
log "Building PowerShell"
Start-PSBuild -UseNugetOrg -Clean -PublishLinkPath debug

# Prebuild more if in a codespace, otherwise leave this to the user to optimize local startup time
if ($ENV:CODESPACES) {
log 'Prebuilding Tests'
dotnet build test/xUnit
Comment thread
JustinGrote marked this conversation as resolved.
log 'Fetching Pester for Tests'
Restore-PSPester
log 'Build Testing Tools'
Publish-PSTestTools
Publish-CustomConnectionTestModule
}
1 change: 1 addition & 0 deletions 1 .devcontainer/scripts/3-postCreate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Docs: https://containers.dev/implementors/json_reference/#lifecycle-scripts
1 change: 1 addition & 0 deletions 1 .devcontainer/scripts/4-postStart.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Docs: https://containers.dev/implementors/json_reference/#lifecycle-scripts
1 change: 1 addition & 0 deletions 1 .devcontainer/scripts/5-postAttach.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Docs: https://containers.dev/implementors/json_reference/#lifecycle-scripts
19 changes: 19 additions & 0 deletions 19 .devcontainer/scripts/shared.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function log ([string[]]$message) {
$message = $message -join ' '
Write-Host -ForegroundColor Cyan $message
}

#Devcontainer scripts should have their CWD set to the workspace folder, so we use this for our needed paths
$SCRIPT:WorkspaceFolder = $PWD

# Suppresses ANSI Output in Codespaces Build Output
# $env:CODESPACES is a "magic variable" in the codespaces CI that can be used to detect it
if ($env:CODESPACES) {
[Environment]::SetEnvironmentVariable('TERM', 'dumb', [EnvironmentVariableTarget]::User)
[Environment]::SetEnvironmentVariable('TERM', 'dumb', [EnvironmentVariableTarget]::Process)
$ENV:TERM = 'dumb'
$ENV:NO_COLOR = $true
$ENV:DOTNET_CLI_CONTEXT_ANSI_PASS_THRU = $false
$ENV:DOTNET_CLI_CONTEXT_VERBOSE = $false
$PSStyle.OutputRendering = 'PlainText'
}
1 change: 1 addition & 0 deletions 1 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ obj/
project.lock.json
*-tests.xml
/debug/
/debug
/staging/
/Packages/
*.nuget.props
Expand Down
10 changes: 5 additions & 5 deletions 10 .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// See https://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"editorconfig.editorconfig",
"ms-azure-devops.azure-pipelines",
"ms-vscode.cpptools",
"ms-dotnettools.csharp",
"ms-dotnettools.csdevkit",
"ms-vscode.PowerShell",
"twxs.cmake",
"GitHub.vscode-pull-request-github",
"ms-azure-devops.azure-pipelines",
"editorconfig.editorconfig",
"DavidAnson.vscode-markdownlint",
"vitaliymaz.vscode-svg-previewer"
"esbenp.prettier-vscode"
]
}
13 changes: 8 additions & 5 deletions 13 .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch",
"name": "PowerShell Dev Console",
"type": "coreclr",
"request": "launch",
"justMyCode": false,
"stopAtEntry": true,
"program": "${workspaceRoot}/debug/pwsh",
"preLaunchTask": "Build",
"externalConsole": true,
"console": "integratedTerminal",
"justMyCode": false,
"stopAtEntry": false,
Comment thread
JustinGrote marked this conversation as resolved.
"logging": {
"moduleLoad": false,
"exceptions": false // PS throws a lot of caught exceptions and this clutters output view.
},
"cwd": "${workspaceRoot}"
},
{
Expand Down
26 changes: 21 additions & 5 deletions 26 .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
// Place your settings in this file to overwrite default and user settings.
{
// This is the default. EditorConfig *should* override this on a per language basis.
"editor.tabSize": 4,
"editor.insertSpaces": true,

"files.insertFinalNewline": true,

// These are defaults but explicitly specified to override any user local preferences
"omnisharp.enableEditorConfigSupport": true,
"prettier.useEditorConfig": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,

// Only format changed code, as lots of code may not meet current format standards.
"editor.formatOnSaveMode": "modifications",

// We leave this one up to the user
// "editor.codeActionsOnSave": {}

// Configure Prettier for formatting
// PowerShell and C# use their respective extension formatters
// Markdown uses markdownlint
"[json][jsonc][yaml][shellscript][html][javascript][typescript][properties]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},

// Based on current .markdownlist.json settings:
// https://github.com/PowerShell/PowerShell/blob/master/.markdownlint.json
"markdownlint.config": {
Expand Down Expand Up @@ -33,8 +52,5 @@
"powershell.codeFormatting.whitespaceAroundOperator": true,

// Adds a space after a separator (',' and ';').
"powershell.codeFormatting.whitespaceAfterSeparator": true,

// Omnisharp : Enable EditorConfig support
"omnisharp.enableEditorConfigSupport": true
"powershell.codeFormatting.whitespaceAfterSeparator": true
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.