I want to use PowerShell to run a script that:
Launches Visual Studio Developer Command Prompt (VS 2017)
Enters in sequence of commands to do a batch and release build
%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat" && <next sequence of commands to do batch build>
The above code simultaneously opens VS Dev prompt and my sequence of commands. There is no pause after opening the prompt, so the commands do not run.
Screenshot of what happens
Related
Is it possible to open a file using debugger commands options of Visual Studio?
For example I want to run my program (with some command arguments) and then open a file.
The cmd equivalent would be:
app.exe args & file.png
Can I do the same thing in visual studio using projects settings or any other way?
You can use dev command prompt inside Visual Studio to achieve the same result
You can open Developer Command Prompt from Tools > Command Line menu
Then just type in whatever command you use in cmd
I'm writing a powershell script that remotely gets the workspace info on a remote computer's TFS.
What I need to do is either invoke-command or psexec the path of the batch file to open up the visual studio dev command prompt, and then run a command inside that prompt. What I'm having trouble with is executing the second command inside the dev command prompt. What is happing right now is I'm able to open the dev command prompt, but only when I exit it does the second command run. Below is some code I was trying.
.
Invoke-Command -ComputerName computer1 {cmd /k '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\LaunchDevCmd.bat" & tf'}
^ I get a tf is not recognized, which it isn't when in a normal command prompt. If it ran in the dev prompt I'd get some version info and help commands.
.
#echo off
"C:\Users\me\Downloads\PSTools\PsExec.exe" \\computer1 cmd /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\LaunchDevCmd.bat" & "tf"
^ This opens the dev prompt, and upon exiting it gives an error that tf is not a command.
.
What I want to do is: Normal Prompt > Dev Prompt > Run Command > Leave Both. Is this possible? Is there a way to just start at the dev prompt?
You could invoke tf.exe command in your powershell directly:
PS> & "$env:Program Files (x86)\Microsoft Visual Studio\2017\\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\tf.exe" #("workspace", "/new", "xxx", "/noprompt", "/login:xxx,xxx", "/collection:xxx")
I want to create a .bat file that will open Developer command prompt and there i need to change directory "cd .. " path " " and execute few commands there.
The Developer Command Prompt for Visual Studio is nothing more as the normal cmd with a bat script run at the start.
You can run this script by yourself.
call "%programfiles(x86)%\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
Working on this now.
my current .txt file has a hanged extension of (.bat) Which is batch.
Copy & Paste this within your batch file.
echo off
title My Test Batch File
:: See the title at the top.
echo Test file executed.
echo I am too lazy to write commands again and again.
C:\Program Files (x86)\Microsoft Visual Studio 14.0>
pause
Right Click on your project name under solution explorer, then locate open command line, select developer command Prompt or use shortcut: shift + Alt + ,
I want to know what is the command I should execute in the command window of the visual studio 2013, to change directory to:
C/:Users/user/Documents/Visual Studio 2013/Projects/OutlookAddin/publish/<Most_Recent_Version>/OutlookAddin_TemporaryKey.pfx
What is the command I must execute?
Actually, cd cmd works, but in a bit diff like this:
syntax:
cd /d c: or e: etc..
where /d stands for drive
for instance:
cd /d C/:Users/user/Documents/Visual Studio 2013/Projects/OutlookAddin/publish//OutlookAddin_TemporaryKey.pfx
No need for the single or double quote in this case.
Now to execute any type of files for instance simply add '.\' before the executed one.
syntax:
.\OutlookAddin_TemporaryKey.pfx or .\example.exe what so ever
cd does work. However, keep in mind that if the path you're trying to get to has spaces, you need quotes around it (the path). E.g.:
cd "C:\Program Files\Microsoft Visual Studio 10.0" Also, note that the
"Visual Studio command prompt" that is mentioned in Step 6 is not the
"Visual Studio Command Window" - I think this is where the problem
comes from. The command prompt is a separate executable that you can
start by clicking Start, point to All Programs, point to Microsoft
Visual Studio, point to Visual Studio Tools, and then click Visual
Studio Command Prompt. Alternatively, just search "Visual Studio" in
the search bar in the Start menu, and it should show up
Source: Using the Command Window in Visual Studio
First create a file on CMD (COMMAND PROMPT)
1.cd desktop
2.mkdir filename
3.cd filename
4. code .
(It has to be a space between code and the dot to open up the file in visual studio code)
Note: If you just want to open visual studio, then go to CMD and just type in 'code' without the dot.
How to set the default visual studio command prompt location so that I can go straight to my project's directory instead of using the usual navigation.
For Visual Studio 2017 Command Prompt, you need to set environment variable VSCMD_START_DIR to the directory where you want to end up after the command prompt initializes.
I use this script:
set VSCMD_START_DIR=%1
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
It accepts the directory as the first (and only) argument.
Add it as an external tool to Visual Studio (2008 shown here, should be similar in other versions):
Select "Tools", "External Tools...".
Click Add
Title: &Cmd
Command: cmd.exe
Arguments: /k "c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
Initial Directory: $(SolutionDir)
Note the arguments come from the "Visual Studio 2008 Command Prompt" shortcut. Yours may vary.
You can can customize the toolbar and add a button for this command as well using "Tools", "Customize...". Open the Tools menu and locate the last External Tool you created and drag it onto the toolbar.
When you click the button, it will open a command prompt in the current solution's root directory.
In Visual Studio 2013,
Right click on "Developer Command Prompt for VS2013" shortcut (which you can find in the "Common7\Tools\Shortcuts" folder from where you installed your VS2013) and choose "Properties",
Change the: "Start in: " directory to your desired location.
Navigate to the "vcvarsall.bat" file. For me the path is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat
Add this line to the bottom of the script:
cd /d "D:\WhereverYouWant"
skol
For Developer Command Prompt for VS 2019 you can set VSCMD_START_DIR environment variable with the following command:
setx VSCMD_START_DIR C:\your-folder
You can put these lines in a batch script (vcvar.bat) located in the directory you want to start with:
#echo off
set VCDIR=%ProgramFiles%\Microsoft Visual Studio 10.0\VC
if not exist "%VCDIR%" set VCDIR=%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC
call "%VCDIR%\bin\vcvars32.bat"
Fire a command prompt in this directory, and call vcvar.bat. You now have the VS environment in the command prompt.
Copy Windows Command Processor from "C:\Windows\System32\cmd.exe" and paste to "C:\Your\Project\Directory\cmd.exe"
Edit Visual Studio Command Prompt shortcut by replacing %comspec% with "C:\Your\Project\Directory\cmd.exe" in the Target field.
So the shortcut's Target should look something like: "C:\Your\Project\Directory\cmd.exe" /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" amd64
this will add a menu entry "my compiler " to each directory giving you access to the command prompt in the directory.
save it as something.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\My Compiler]
[HKEY_CLASSES_ROOT\Directory\shell\My Compiler\command]
#="cmd.exe /k \"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\vcvarsall.bat\""