Closing powershell window closes my program as well - powershell

This is my first attempt at automating some of my development environment setup. I have the following powershell script:
& "C:\MAMP\MAMP.exe"
& "C:\Program Files\Microsoft VS Code\Code.exe"
I run it and it works fine, but when I close the powershell window it closes my VS Code window as well. MAMP stays open.
I'm sure this is a simple fix. Thanks!

Have you tried with Start-Process?
Start-Process "C:\Program Files\Microsoft VS Code\Code.exe"

Related

VS Code opened via VS Developer Command Prompt not recognizing 'cl'

As the title says, VS Code is not recognizing cl compiler although opened via Visual Studio 2022 Developer Command Prompt:
VS Code terminal:
I have tried using VS Code external terminal with %comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
which did not work.
Setting the comspec manualy in the terminal did solve the issue for the terminal instance:
But the C++ extension is still complaining about cl.exe:
cl.exe build and debug is only usable when VS Code is run from the Developer Command Prompt for VS.
I have never used VS Code for C++ before and I don't use windows for development at all so go easy on me.
What could be the reason for the issue and how it can be solved?
Visual Studio Developer Command Prompt must be elevated(run as Administrator) in order to correctly open VS Code with the needed permissions.
Running Visual Studio Developer Command Prompt as Admin solves the issue.
One solution that worked for me is to go directly in the setting for C++ extension and find compiler path setting, and manually set it to cl.exe path on your computer.

Can I debug ActiveDirectory with Visual Studio Code PowerShell extension?

It looks like the Visual Studio Code PowerShell extension is only able to debug scripts running on PowerShell Core.
Is it possible to debug PowerShell scripts when running PowerShell 5.1? I need to debug scripts accessing Active Directory.
On Windows, yes.
https://code.visualstudio.com/docs/languages/powershell#_multiversion-support
TL;DR: Just click the version number in the lower-right corner.

Can I detect in Powershell that I am running in VS Code's integrated terminal?

I would like to modify the standard PowerShell profile in Windows if the Powershell opens inside VS Code integrated terminal (when you are editing e.g. python scripts in VS Code, rather than PS scripts, which opens the ISE profile in any case).
Is there some environmental variable that gets set by the integrated PowerShell? Or is there some way of opening Powershell with a particular profile, instead of the default?
Thanks
VS Code creates an environment variable named TERM_PROGRAM. You can check it for a value of vscode, something like this:
if($env:TERM_PROGRAM -eq 'vscode') {
# do some stuff...
}
If you want to check if you're running within PowerShell Integrated Console (ships with PowerShell extension) under vscode and not just any powershell console running under vscode, you can:
if ($Host.Name -eq 'Visual Studio Code Host') {
Write-Output 'PowerShell Integrated Console'
}
This is meaningful to detect because it is the only powershell console host that provided full debugger support (eg. break on exception experience) and debugger integration with vscode.
You said you're into modifying profile when running within vscode, then you should check (again with PowerShell integrated console which ships with PoweShell extension):
PS> $PROFILE.CurrentUserCurrentHost
C:\Users\username\Documents\PowerShell\Microsoft.VSCode_profile.ps1
PS> $PROFILE.AllUsersCurrentHost
C:\Program Files\PowerShell\7\Microsoft.VSCode_profile.ps1
If people are working on PowerShell code within Visual Studio Code, then why they would NOT install PowerShell extension which ships with a specific console that fully integrates with Visual Studio code and on the top of that, provides you a profile file specifically geared towards Visual Studio code?

Launching VSCode from terminal keeps posting state updates

I like to navigate to my working dir via GitBash and upon launching VSCode via
code .
the terminal locks up in the process and I have to launch another GitBash to execute my commands. I am having troubles figuring out why its behaving like this since its happening only on 1 out of 3 machines I'm using. Google is so far no luck.
How can I change this to the default behavior I'm used to? On the other two machines it just launches VSCode in the directory where I am at and prompts to a new line to accept further cli commands.
Set State updates VSCode img
Finally found the problem, the issue was in the PATH environment variable. It pointed to Code.exe in
C:\Program Files\Microsoft VS Code
it is supposed to point to
C:\Program Files\Microsoft VS Code\bin

Setting up Visual Studio environment variables from PowerShell [duplicate]

This question already has answers here:
How can I use PowerShell with the Visual Studio Command Prompt?
(15 answers)
Closed 1 year ago.
I have Visual Studio 9.0 installed but I want to use it manually from PowerShell. It comes with two setup scripts: vcvars32.bat for the 32-bit compiler and vcvars64.bat for the 64-bit compiler. When I open cmd.exe and run one of the scripts, it sets up everything just fine and I can run cl.exe without any problems. When I run one of those setup scripts from PowerShell, though, it doesn't work. The scripts run through fine but trying to run cl.exe afterwards yields a "cl.exe could not be found" error! And looking at the contents of the PATH environment variable after running one of the setup scripts I can see that PATH hasn't actually been modified at all.
So it seems as if the batch files ran from PowerShell maintain their own environment variables state which goes away as soon as the batch file terminates. So is there a way to run batch files from PowerShell and have those batch files affect the actual environment variables of the current PowerShell session? Because that is what I need. All that is done by vcvars32.bit and vcvars64.bit is setting up environment variables after all but it only seems to work from cmd.exe, not from PowerShell.
You should use InvokeEnvironment script to do that. Check its man page:
Invoke-Environment <path_to_>vsvars32.bat
You can furhter generalize this by determining OS bits and crafting the vsvars<OsBits>.bat.
Example:
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> $env:INCLUDE -eq $null
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> $true
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> Invoke-Environment .\vsvars32.bat
PS C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools> $env:INCLUDE
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt;
I don't have Visual Studio at hand, but the batch scripts most likely just set variables for the current session. Running them from PowerShell won't do you any good, because they'll be launched in a child CMD process and change the process environment of that process, but not of the parent (PowerShell) process.
I suspect you need to translate the variable definitions to PowerShell, e.g.
set PATH=%PATH%;C:\some\where
set FOO=bar
becomes
$env:Path += ';C:\some\where'
$env:FOO = 'bar'
Write the translated definitions to a .ps1 file and dot-source that file in your PowerShell session:
. C:\path\to\vcvars.ps1