Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows environment variables in powershell.scriptAnalysis.settingsPath #4268

Closed
2 tasks done
o-l-a-v opened this issue Nov 17, 2022 · 4 comments
Closed
2 tasks done
Labels
Area-Configuration Issue-Enhancement A feature request (enhancement). Resolution-External Will close automatically.

Comments

@o-l-a-v
Copy link
Contributor

o-l-a-v commented Nov 17, 2022

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.windows setting.
      • Example: "path": "${env:LOCALAPPDATA}\\Microsoft\\WindowsApps\\Microsoft.PowerShell_8wekyb3d8bbwe\\pwsh.exe"
  • 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?

Relevant doc

@o-l-a-v o-l-a-v added the Issue-Enhancement A feature request (enhancement). label Nov 17, 2022
@ghost ghost added the Needs: Triage Maintainer attention needed! label Nov 17, 2022
@andyleejordan
Copy link
Member

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 andyleejordan added Area-Configuration and removed Needs: Triage Maintainer attention needed! labels Nov 30, 2022
@andyleejordan
Copy link
Member

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.

@andyleejordan andyleejordan added the Resolution-External Will close automatically. label Dec 7, 2022
@ghost ghost closed this as completed Dec 7, 2022
@ghost
Copy link

ghost commented Dec 7, 2022

This issue has been marked as external. It has been automatically closed for housekeeping purposes.

@o-l-a-v
Copy link
Contributor Author

o-l-a-v commented 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:

# Assets
$Source      = [string] '{0}\PSScriptAnalyzer.psd1' -f $env:PUBLIC
$Destination = [string] '{0}\_Share\AppData\PowerShell\Settings - PSScriptAnalyzer.psd1' -f $env:OneDriveConsumer

# Create symlink (requires admin unless Windows developer mode is enabled)
New-Item -ItemType 'SymbolicLink' -Path $Source -Value $Destination -Force

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-powershell inside VSCode settings.json:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Configuration Issue-Enhancement A feature request (enhancement). Resolution-External Will close automatically.
Projects
None yet
Development

No branches or pull requests

2 participants