Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Powershell extension does not recognize profile while debugging

I’m using the Powershell extension for Visual Studio Code. I updated the profile:

C:\Users\xxxxxxxx\Documents\WindowsPowerShell\Microsoft.VSCode_profile.ps1

To include some functions and variables that I want to make available to other scripts. When I reference a variable from the profile within another script, it does not appear that the profile has been loaded. I suspect this because the variable value is blank when I query it from the VS Code console. If I run the same test from the standard Powershell console with an associated profile, the variable value is resolved.

Can anyone tell me what, if anything, I need to do to use a Powershell profile in VS Code while debugging?

like image 674
rrirower Avatar asked Aug 28 '26 20:08

rrirower


1 Answers

There are several profiles. The starting point is the four locations that you can find by reading the following properties of PowerShell's built-in $profile variable.

$profile.CurrentUserAllHosts
$profile.CurrentUserCurrentHost
$profile.AllUsersCurrentHost
$profile.AllUsersAllHosts

As noted in this article by The Scripting Guy, because Windows has both Powershell and the Powershell ISE, you have at least two possible values of Current Host, so at least 6 profiles.

I've tested this in the Visual Studio Code terminal window, and it seems that the "CurrentHost" profiles are the same as you get by simply running a powershell instance. I'd assume then that Code isn't seen as a distinct host, and just runs a normal powershell. Once you've got that far, there's another possible complication, which is that the AllUsers profiles are down in C:\Windows\System32 and hence on a 64 bit system, also mirrored in C:\Windows\SysWOW64\. So depending on whether you are using a 32 or 64 bit editor, and whether the Powershell is hosted in a 32 or 64 bit process, it is quite possible that the file you are editing has no influence on the Powershell.

like image 200
Dominic Cronin Avatar answered Aug 30 '26 15:08

Dominic Cronin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!