Repository navigation
Closed
Labels
Area-ConfigurationIssue-EnhancementA feature request (enhancement).A feature request (enhancement).Resolution-ExternalWill close automatically.Will close automatically.
Description
Prerequisites
- I have written a descriptive issue title.
- I have searched all issues to ensure it has not already been reported.
Summary
I'd like to be able to use Windows environment variables inside settings.json powershell.scriptAnalysis.settingsPath.
From my testing it does not currently seem possible.
Why?
I'd like to be able to easily sync both Visual Studio Code settings.json and PSScriptAnalyzer settings file between devices.
Windows explorer
Path in Windows Explorer that resolves:
%OneDriveConsumer%\_Share\AppData\PowerShell\Settings-PSScriptAnalyzer.psd1
Settings.json
In settings.json I've tried the following.
Works (hard coded)
"powershell.scriptAnalysis.settingsPath": "C:/Users/<removed>/OneDrive/_Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"Does not work
Neither of these works.
"powershell.scriptAnalysis.settingsPath": "${env:OneDriveConsumer}/_Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "${env:OneDriveConsumer}\\_Share\\AppData\\PowerShell\\Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "${userHome}/OneDrive/Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "${userHome}\\OneDrive\\Share\\AppData\\PowerShell\\Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "%OneDriveConsumer%/_Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "%OneDriveConsumer%\\_Share\\AppData\\PowerShell\\Settings-PSScriptAnalyzer.psd1"Proposed Design
- Add this ability if it does not exist already
- Preferably in the same syntax used for environment variables inside the
terminal.integrated.profiles.windowssetting.- Example:
"path": "${env:LOCALAPPDATA}\\Microsoft\\WindowsApps\\Microsoft.PowerShell_8wekyb3d8bbwe\\pwsh.exe"
- Example:
- Preferably in the same syntax used for environment variables inside the
- Document how to use it
- Path separator?
\,\\,/- Does it vary per OS?
- How to represent a environmental variable?
%APPDATA%,${APPDATA},${env:APPDATA}- Does it vary per OS?
- Path separator?
Relevant doc
Metadata
Metadata
Assignees
Labels
Area-ConfigurationIssue-EnhancementA feature request (enhancement).A feature request (enhancement).Resolution-ExternalWill close automatically.Will close automatically.
Activity
andyleejordan commentedon Nov 30, 2022
Unfortunately, extension-provided settings such as this are explicitly not parsed for variable resolution by VS Code, and doing so in a post-processing manner would be quite difficult to get right. It's a neat idea, and I see the desire for it, but probably not something we're prioritizing at this point.
I would point you toward VS Code setting profiles as a different approach to solve your problem.
andyleejordan commentedon Dec 7, 2022
Please see microsoft/vscode#46471 for more context as to my contributed settings (like ours) can't support VS Code built-in (nor environment, through
env:) variables.o-l-a-v commentedon Jun 17, 2024
In case it help others: I've got this working using a symlink from
%PUBLIC%\PSSCriptAnalyzer.psd1, which will be the same path on multiple systems. I symlinked it like so:Then in VSCode
settings.json:{ ... "powershell.scriptAnalysis.settingsPath": "C:\\Users\\Public\\PSScriptAnalyzer.psd1", ... }I'd prefer if VSCode could use environment variables inside VSCode
settings.json:Or the ability to configure PSScriptAnalyzer for
vscode-powershellinside VSCodesettings.json:o-l-a-v commentedon Nov 17, 2026
Andy Jordan (@andyleejordan)
The VSCode Python extension accepts env variables. This works.
{ "python.defaultInterpreterPath": "${env:USERPROFILE}/scoop/apps/python/current/python.exe" }This code looks relevant: