How to ensure vsvars32.bat has run - command-line

I have a build process using MSVC 2005. It only works correctly if run from a Visual Studio command prompt, not from a regular command prompt, because of the additional variables that get set. It's far too easy to run the wrong type of prompt and then get obscure error messages, so I'm trying to avoid this. I don't want to change my regular command prompt to always call vsvars32.bat, since I don't always want this, but I wanted to add a message to suggest using the Visual Studio Command Prompt. To do this, I wrote a BAT file
if "%VSINSTALLDIR%" == "" echo Did you want a Visual Studio Command Prompt?
However, this also shows up in the Visual Studio Command Prompt because it gets called before vsvars32.bat does.
Does any one have any idea how I could get a message added to a normal command prompt but not the Visual Studio 2005 Command Prompt? I suspect from how the Visual Studio Command Prompt is set up this isn't possible.
Thanks.

Why not execute vsvars32.bat from within your build process? The other option is to explicitly spawn a shell using something like cmd.exe /k path-to-vs\vsvars.bat - IIRC, the /k option makes the shell execute the argument and remain open.

Related

How do I stop Visual Studio Code from opening after I try to execute a .pl file from Command Prompt?

I use command prompt to run a file.pl and every time I do Visual Studio Code keeps auto launching and showing me the lines of code. I don't want it to open, just run the file in command prompt.
see above, it's pretty self explanatory

When typing commands in Visual Studio Code terminal window, it suggests command parameters and values

The problem can be seen on the screenshot :
I have a powershell function in the memory and when I try to write it as a command in the terminal window, VSCode automatically makes some suggestions for the values of the parameters. How can I turn this off?
1

Dedicated Command History panel in VS Code

I'd find it convenient to be able to quickly recall past commands issued in the terminal. In Matlab one can simply select any number of those from the Command HIstory panel, and reissue them in the Terminal all at once:
In VS Code (on Windows), I know there is a command to pull up the log text file:
(Get-PSReadlineOption).HistorySavePath
But I find this extremely cumbersome as a solution to call up multiple lines at a time. Is there an VS Code addon that creates a Matlab-like Command History panel with timestamped commands (didn't find any searching myself)? Or is such feedback taken into consideration by Microsoft?
See v1.70 release notes:
Triggering the Terminal: Run Recent Command... will bring up a QuickPick panel of recent terminal commands in which you can search, fuzzy or not, through the recent commands.
There are some examples of commands for going to the next item in the list, for example.
See the supported shells and OS's mentioned below. I believe it is still accurate. Git Bash on Windows doesn't work with this new recent command functionality, but powershell does. Support for MacOS and linux is stronger: bash, powershell and zsh.
And see v1.69 release notes: run recent command:
Some other functionality of the command:
In the current session section, there is a clipboard icon in the right
of the Quick Pick that will open the command output in an editor. Alt
can be held to write the text to the terminal without running it. The
amount of history stored in the previous session section is determined
by the terminal.integrated.shellIntegration.history setting.
There is currently no keybinding assigned by default but it can be
hooked up to Ctrl+Space for example with the
following keybinding:
{
"key": "ctrl+space", // whatever keybinding you want
"command": "workbench.action.terminal.runRecentCommand",
"when": "terminalFocus"
}
This might help (coming to v1.64):
Terminal shell integration
The terminal now features experimental opt-in shell integration which
allows VS Code to gain insights on what is going on within the
terminal as it was previously a black box. When enabled using
"terminal.integrated.enableShellIntegration": true, arguments to run
a shell integration script will be injected into your terminal profile
if possible. The script itself mostly just injects invisible sequences
into your prompt, providing us with information like where the prompt,
command and command output is, what the current working directory
(cwd) is for each command and the exit code of each command.
Shell integration enables the following new features:
Run recent command: Since we know what commands are run, we have
exposed a command that allows you to view and run them again in a
quick pick.
Developer: Run Recent Command run this command from the Command Palette
The current shells supported are pwsh for Windows and pwsh, bash and
zsh for Linux and macOS.
from release notes: terminal shell integration
Although I switched to powerShell on W11 to test this feature - which should be supported - I can't get it to work just now. I wanted to see if you could pick multiple command entries in the QuickPick to run a series of them, but I doubt you can. But at least you get a nice list of recent commands.

F8 or "Run Selection" not working in VS Code while trying to run powershell commands in terminal

I am using VS Code and i have my powershell terminal in VS Code as well as Powershell ISE. I have my own personal script file in the form of .ps1 which has some list of commands. When i select a command in the file and right click and choose "Run Selection" , that doesn't get reflected in the Powershell Terminal in VS code. I even tried Function + F8 key of the laptop, still the same. Any idea what do i need to do to fix this.
I had the same issue, F8 stopped running selected script suddenly. Had to reinstall the PowerShell extension for VScode and it fixed it.
Check key bindings as well by hitting Ctrl+K, Ctrl+S and search "Run Selection". This should be a sub function of the PowerShell extension.
I ran into a similar problem and I came into the solution. Just install the powershell extension for VS code and you'll see the Run Selection/F8 work.

MSTest from command line

I am trying to run MSTest from command line in powershell.
mstest /testcontainer:Common.Tests.dll
I am in the project bin/debug folder. It opens a new command window and the window closes either with no output or output that I can't read, as a result of the window immediately closing. The test run successfully in Visual Studio and the project builds successfully using MSBuild and in Visual Studio. I assume that something is breaking but I have no idea how to determine what it could be.
I am using VS 14.0.
I have also tried vstest.console with the same result.
Well, one way to do that would be:
mstest /testcontainer:Common.Tests.dll > result.txt 2>&1
that would redirect all output to the result.txt
You can assign the output to a variable and then use it however you wish, like just outputting it to screen...
$mstest = Invoke-Expression "mstest /testcontainer:Common.Tests.dll"
Write-Output $mstest