Access Visual Studio Developer Command Prompt from regular Command Prompt - windows

This related question shows how to build and run a Visual Studio solution from Visual Studio Developer Command Prompt. My question is, is it possible to build and run a Visual Studio solution directly from the regular Windows Command Prompt (cmd.exe)?

Finally, I found the answer.
Access VS Developer Command Prompt from regular command prompt.
C:\Users\Hwathanie>cmd.exe /k ""C:\Program Files (x86)\Microsoft Visual
Studio 12.0\VC\vcvarsall.bat"" x86
Build the solution.
C:\Users\Hwathanie>msbuild "C:\Users\Hwathanie\Documents\Visual
Studio 2013\Projects\MyProject\MyProject.sln" /p:Configuration=Debug
Run the exe file created.
C:\Users\Hwathanie>"C:\Users\Hwathanie\Documents\Visual Studio 2
013\Projects\MyProject\bin\Debug\MyProject.exe"

Related

Visual Studio: missing Shortcut: "Visual Studio Command Prompt"

Because the VS 2015 Installer was crashing all the time, I had to use the silent installation. Now I don't have the "Visual Studio Command Prompt" Shortcut in Start menu. Can I find it somewhere else?
I had to create the shortcuts manually as well, but they all follow the same pattern so no biggie:
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" x86
Don't forget to change the execution path to: "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\"
Replace the last bit (x86) with the tool you want to use:
x86
amd64
arm
x86_arm
x86_amd64
amd64_x86
amd64_arm
Visual studio command prompt is nothing but the regular command prompt where few environment variables are set by default. This variables are set in the batch script : C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat . So basically to get a visual studio command prompt for a particular version, just open regular command prompt and run this batch script : C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat (Change the visual studio version based on your installed version). Voila you have got the visual studio command prompt. You can write a script to run the batch file and open cmd.exe and have a shortcut for the same.

Use the devenv command to run a specific version of Visual Studio

We have both Visual Studio 2010 and 2012 installed on our machine. Often we want to run it with the devenv command. To be clear, we want to open Visual Studio. How do we pass the version number to run? The devenv command line documentation doesn't say how.

LIB library /EXTRACT:member /OUT:objectfile

Where do I run this syntax? There's no command line on Visual Studio. I know this is a simple question but so far I couldn't find the answer.
Usually, after installation of Visual Studio, you have a submenu entry inside the Microsoft Visual Studio program group called Visual Studio Tools. In this submenu you could find a couple of Command Prompt for ... menu that launch a command window with specific path set to the Tools installed with Visual Studio, including the LIB tool
For example, this is the command executed by one of mine menu entries
%comspec% /k ""c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86_amd64

Visual Studio Command Prompt vs. a regular command prompt?

When I open a Visual Studio command prompt (for example, opened with menu Start -> Programs -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt), I get:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE>
What kind of tools are available, and what are the most common uses of this command prompt?
It basically just sets several of the Visual Studio binary locations into the PATH environment variable for that command window instance. This means you can use all the various commands and tools without having to include the full paths.
There's a partial list of some of the tools available on MSDN in .NET Framework Tools and Tools (.NET Framework).
The Visual Studio command prompt is a convenient way to access the command line tools that ship with the .NET Framework SDK and, if installed the, Windows Platform SDK tools.
By providing the Visual Studio command prompt, Microsoft allows you to run these tools without requiring your PATH, INCLUDE, LIB and LIBPATH environment variables to contain all the additional paths to the various folders where Visual Studio and the .NET SDK are installed. Instead, these folder references are added on the fly when you start the Visual Studio command prompt allowing you to run the tools.
For example, if you open a regular command prompt you cannot run xsd.exe without changing to the directory "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin". However, in the Visual Studio command prompt you can just type xsd.exe /?, and it works.
Please see the MSDN article .NET Framework Tools for a complete list of the tools provided with Visual Studio 2008 SP1 and details on what they do.
The Visual Studio command prompt has a few tools with it. Some tools are for repairing the install of Visual Studio. One of the tools I love using is for WCF. You type wcftestclient and you get a client to test your WCF services.
The article The Visual Studio Command Prompt has a nice explanation:
Let's look at the "Visual Studio Command Prompt" in more detail.
It appears to just set the path for you and put you in (Ta Da!) the VC
directory under Visual Studio. Not even the C# directory and certainly
not the VB directory. I guess they assume that anyone who uses this
tool is really hard core and programs directly against the hard drive
with a magnifying glass and a magnet.
What it actually does is run this DOS command. (In my case.)
%comspec% /k ""C:\Program Files\Microsoft Visual Studio
10.0\VC\vcvarsall.bat"" x86
What does vcvarsall.bat do? Well, it sets the target compiler
environment so you can compile code for a different processor.
One use seems to be to call the XML Class Generator for using XSD schemas for serialization/deserialization:
XML Class Generator for C# using XSD for deserialization
Simple example
After installing Desktop development with C++ as part of the VS Installer, it installs C++ CMake tools for Windows. Let's run this cmake.exe file!
VS Developer Command Prompt
C:\Directory>cmake --version
cmake version 3.21.21080301-MSVC_2
Windows Command Prompt
C:\Directory>cmake --version
'cmake' is not recognized as an internal or external command,
operable program or batch file.
Why example behaves as it does
The VS Developer Command Prompt knew the command cmake, yet the Windows command prompt didn't.
Its almost as if it is and isnt a path variable - Schrodingers cat, errr path!
So where is cmake.exe that the VS developer command prompt says it knows about?
VS Developer Command Prompt
C:\Directory>where cmake
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe
Okay so that means C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\ must be a PATH variable.
Lets double check:
C:\Directory>set PATH
Path=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;
It is, great. Now why didnt the windows command prompt find it?
Windows Command Prompt
C:\Directory>set PATH
Hmmm, I'm looking at the list and its not there.
Now Simon Steven's and MikeD's answer can be put in context:
It basically just sets several of the Visual Studio binary locations into the PATH environment variable for that command window instance. This means you can use all the various commands and tools without having to include the full paths.

Starting Visual Studio from a command prompt

I have three different versions of Visual Studio installed on my machine,
Visual Studio 2003, Visual Studio 2008, and VS2005.
How do I start a particular version of Visual Studio using a command prompt?
devenv.exe opens the latest version of Visual Studio. What should I do if I want to open Visual Studio 2003 using a command prompt?
Haven't tested on preceding versions - but to launch Visual Studio 2019 you can just enter start devenv to launch right away without entering into a path
You have to use the path to distinguish them. For instance, here is the Visual Studio 2005 command on my laptop:
"C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe"
Here's another tip: You can figure out how to run various Windows applications from the command line by finding them in the Windows Start Menu, right-clicking on the icon, select properties, and then on the Shortcut tab, look at the Target textbox. Copy that text out and usually you can use it at a console command line.
This answer is a different way to handle starting Visual Studio in any version of Windows, by using the Windows Key {windows logo} start to start the target application.
Pin each version to the task bar. One way is to right click an active running program and select 'Pin to Taskbar. Or find in the program manager and right click again to pin.
Pin each different version right next to the task bar. For this example pin each version in succession 2003, 2005 and finally 2008. Make sure they are next to the start button for easier index number memorization.
To launch the 2003 version hit the WindowsKey then number 1.
To launch 2005 WindowsKey 2.
To launch 2008 WindowsKey 3.
This is fast and easy and can launch multiple instances without bringing up the command console.
Use devenv.exe for the specific version of Visual Studio. There will be one located in the Common7\IDE folder of the install. Here are the directories as I remember for the various versions.
2008:
%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\Ide\devenv.exe
2005:
%ProgramFiles%\Microsoft visual Studio 8\Common7\Ide\devenv.exe
For Visual Studio on a mac, you can:
open '/Applications/Visual Studio.app' [path_to].sln
I create an alias in my bash_profile so I can just navigate to a directory and open it in VS:
echo "alias vs=\"open '/Applications/Visual Studio.app' *.sln\"" >> ~/.bash_profile
Here is the shortcut, You can just type devenv.exe and start visual studio
You can also use the "Visual Studio 2005 Command Prompt" and "Visual Studio 2008 Command Prompt" to load a version-specific command shell environment, and then run devenv. This is typically found under Start -> Programs -> Visual Studio -> Visual Studio Tools
If you can't or don't want to access it via the Start menu, you can also "load" the VS-version specific environment in a normal command shell using the following (for VS 2008,
with a default install path): (note: change x86 as appropriate for your platform)
(32 bit) %comspec% /k ""C:\Program Files\Microsoft Visual Studio 8\VC\vcvarsall.bat"" x86
(64 bit) %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 8\VC\vcvarsall.bat"" x86
or for VS 2008 (with default install path):
(32 bit) %comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
(64 bit) %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
Each sets the environment so if you then subsequently execute devenv it'll load the correct version.
Put C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\ in the path of your computer.
Then open a new command prompt.
Change the directory to your project folder.
Type devenv to open the project in Visual Studio from the command prompt. This opens the project up in folder view. It has to have a .sln file to do the next part.
Click the switch views drop-down arrow and choose the .sln file.
The solution explorer will now display the solution.
Use an abolute path, for example, C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe.
1) devenv (to open VS)
2) devenv *.sln (then tab to autocomplete and enter to open VS and auto-load current solution)
By default, this only works in Developer Command Prompt.
To make it work in a normal console (I use cmder) you need to add folder path to devenv.exe to the System environment variable name Path.
For me that is this one:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE
You can also use this script and save it as vs.bat and then it will find for you *.sln file in the folder and automatically open visual studio with solution loaded (as in 2.)
Similar question where I answered: Visual studio: How to open a specific solution directly from command line?
Essentially use OpenVSSolution
Put this helper exe somewhere in your PATH
The exe scans the current directory for a .sln file
The exe opens devenv passing in the sln file
The explanation is on here: https://davemateer.com/coding/2018/11/14/Publish-dot-net-core-console-application.html
I find this incredibly useful and is how I open all solutions.
Use Window Terminal (https://github.com/microsoft/terminal), run these commands in the terminal
cd your-project-folder
.\your-solution.sln
I tried the answer that has been accepted in this question but it didnt work for me
I was able to launch Visual studio from RUN by typing devenv.exe in it.
WIN+R didnt work for opening RUN, so in command prompt, I typed the below path in command prompt
c:\WINDOWS\system32\rundll32.exe shell32.dll`,#61
use this command:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe
You can create a bat script for any visual studio version. You can find my script below.
start /B "" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe"
Even, you can create an alias following this post
Go to your project directory in cmd. (ex. cd <=FOLDER_PATH=>)
type code and press enter.
To open it with Visual Studio Express 2012 for Windows Desktop do -
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\VsDevCmd.bat""
%comspec% is:
C:\Users\Admin>echo %comspec%
C:\Windows\system32\cmd.exe
Or just search "developer" in the Windows 8 Start Search "Apps" menu, and it will lead you to "Developer Command Prompt for VS2012".

Resources