" 'devenv' is not recognized as an internal or external command ..." - visual-studio

Is there a way to just open a VS project from the command prompt? For example, the way with Atom, you can navigate to the folder you'd like to open and just run "atom ." Does that kind of utility exist for VS?
edit: Would the equivalent to this be "C:\> devenv /run SomeSolution.sln" ?
if so, great! But there still seems to be a problem because I think the "devenv" command should at least be recognized, but I currently get
'devenv' is not recognized as an internal or external command,
operable program or batch file.
I saw that a S/O contributer recommended adding
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\devenv.exe
to the PATH environment variables values like this, per MSDN, which I did, but I get the same message.
Can anyone explain what might be going on and how to fix it? Thanks

You need to add new path to existing Path value.
Complete solution:
Go to MyComputer >> Properties >> Change Settings >> Advanced >> Environmental variables
Click on Path value on bottom pane, and then click Edit.
Add new path to your devenv.exe folder location.
For me this is "D:\Program Files\Microsoft Visual Studio Community 2017\Common7\IDE\"

This is much easier than it looks. Go to the root directory for the project, type the name of the .sln file, and hit Enter. Windows knows how to use the registry o find devenv.exe based on the extension of the file you run.
For example:
cd \Projects\SampleApp
SampleApp.sln
This technique is the same as if you opened the sln file by double clicking it in Explorer.

On similar issue, for VS 2017, I wanted to build a solution, below worked fine:
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.exe" Project.sln /build

VS 2019 Community
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe
Any Visual Studio Version
To find your specific devenv.exe path regardless of VS copy/version you can use cmd and then run:
cd \
dir /s divenv.exe
Note: The command dir /s may take a few minutes to find it.

Since I had no desire to update my PATH variable, I used the following steps to run devenv on the command prompt:
Navigate to the Visual Studio shortcut on the Start menu
Right-click the shortcut
Click on properties
Copy the path displayed in Target. This is the path to whatever version of devenv that you use.
Paste the copied path into the command prompt and press enter

Related

Visual studio: How to open visual studio in current folder from cmd line

Does anyone know how to open Visual studio from the command line from the current
working directory. I know that when using VS code this is very simple. You just type code . and it works. Here, I'm searching for the Visual studio equivalent.
Anyone an idea?
Found it:
devenv ./mysolutionname.sln
To get this to work, you need to make sure that devenv is contained in your PATH variable.
Also you need to run this cmd as an administrator. You can open a window from your file explorer in your current folder as an administrator, by typing ALT-F and then use arrow button||letters to navigate. Press Enter on cmd|powershell as administrator.
Tip: If you start from an empty folder, you can use dotnet-cli to create a empty sln file
dotnet new sln mysolutionname
Also you can create a new project and add it to the solution using the dotnet-cli
dotnet new console -n myprojectname
dotnet sln add myprojectname
According to the documentation there's no such switch. There is no way to set the curent working directory. But you can open an existing solution.

How to create a shortcut for F# compiler (Fsc.exe)?

I have a stupid question to ask. I have just started learning F#, and I am trying to compile some basics examples (such as HelloWorld.fs).
I created a simple F# file whose path is: C:\FSharp\HelloWorld.fs.
In order to compile it, I used the full path of the F# compiler as follows:
C:\FSharp>"C:\Program Files\Microsoft F#\v4.0\fsc.exe" HelloWorld.fs
It worked perfectly.
However, I do not want to keep writing the full path of the complier: C:\Program Files\Microsoft F#\v4.0\fsc.exe. I tried to add it to Windows path,but I keep getting the error fsc is not recognized as internal or external command.
How can I create a shortcut word for F# compiler so that I don't have to use the full path everytime I need to compile a program?
For those arriving here in 2019 having received F# as a component of Visual Studio 2017. The location of the F# compiler is as follows:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\FSharp\fsc.exe
Take careful note of the Version Type (Community in this case) and adjust yours accordingly.
You don't really need to create a shortcut for this, you just need to add the folder containing fsc.exe to your PATH variable.
When you open the command prompt, run this:
set PATH=%PATH%;"C:\Program Files\Microsoft F#\v4.0\"
or, if you're using a 64-bit version of Windows:
set PATH=%PATH%;"C:\Program Files (x86)\Microsoft F#\v4.0\"
The most recent version of fsc.exe can be found in these locations :
"C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0" // as of Aug 2014
"C:\Program Files (x86)\Microsoft SDKs\F#\3.0\Framework\v4.0" // 2013
I tried setting it to my path, but unfortunately it did not work. Tried logging off/restarting etc. I believe it is because of security measures in place on my work computer.
For other people having similar issues, I found that setting the alias not only worked but was more preferable over other methods.
set-alias fsi "C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\fsi.exe"
set-alias fsc "C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\fsc.exe"
Now the commands don't have the annoying .exe file extension.
Helpful in getting setup was this article on creating persistent aliasing for powershell.
http://www.powershellpro.com/powershell-tutorial-introduction/tutorial-powershell-aliases/
I can confirm that adding the directory to your PATH variable should do the trick (works on my machine!) Note that you may need to restart any opened command line (or, just to make sure, the system) until the change is taken into account if you change the PATH variable in system properties.
You could also create a bat file with something like:
echo off
"C:\Program Files (x86)\Microsoft F#\v4.0\fsc.exe" %*
And then make sure the bat file is somewhere in your PATH. But the bat file can have a different name (say fsharpc.bat), in case there is some name clash between the standard name fsc and something else on your system...

Visual Studio Command Prompt (2010) can't find paths / includes

I am trying to use this tutorial from MS to verify I can build a .cpp file from the command line on my system. I seem to be having problems with my VS Command Prompt. It cannot find cl.exe or the needed include files. I added C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin and C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE to my path so it would find cl.exe. Now my error is:
test.cpp(1) : fatal error C1034: iostream: no include path set
Isn't the whole point of the VS Command Prompt to setup all these environment vars for me? Why isn't it setting it up properly?
I'm not sure exactly what your problem is but you might want to do the following to help determine the actual cause.
You may have noticed that the VS command prompt shortcut is a bat file. The first line is
#echo off
Change it to
REM #echo off
Run it again and see if you get any errors. If you don't it may be in one of the processor specific batch files to know which one that is look for the call to other batch like this.
C:\Program Files\Microsoft Visual Studio 10.0\VC>call "C:\Program Files\Microsof
t Visual Studio 10.0\VC\bin\vcvars32.bat"
Setting environment for using Microsoft Visual Studio 2010 x86 tools.
Again REM out the #echo off in the batch and then run it again and see what errors you get.
Update from comment
The error ERROR: Cannot determine the location of the VS Common Tools folder
means your missing the Environment Variable %VS100COMNTOOLS% which is usually set to
"c:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\"
You can simply add it back using system properties -> Advanced -> New (under system variables)
See this superuser question for more on environment variables
I just figured it out. Thanks to Conrad Frix for the debugging tip.
It is surely due to some lovely security policy I have here on my workstation. Running the shortcut as administrator works. My account is a local admin account, but the admins do all kinds of weird stuff to our machines here...sigh. So, much of our development has to happen by "elevating".
Note, I was able to change the shortcut to run as under administrative privileges by selecting Properties->Advanced->Run as administrator.

MS C++ 2010 and mspdb100.dll

Microsoft's C++ compiler and linker seem to have an odd relationship with mspdb100.dll. When run from the IDE, of course, the compiler and linker work fine. When running either one from the command line, I get an error.
No problem, I located the DLL and copied it to the directory. Now the compiler works fine, but the linker dies.
I could solve the problem by adding "%VS10%\Common7\IDE" to my PATH, but for various reasons (performance, system purity, OCD, etc), I don't want to do that. Why is this setup so touchy, and is there anything else I can do to solve it?
try running path\to\VC\bin\vcvars32.bat from within your current shell first. This should ensure your command-line setup will match the IDE-setup.
This is not a permanent fix -- you need to do it every time you launch a new shell.
You could probably also find some way to add everything that's in that .bat permanently to the environment variables, but.... like you asked, why the heck doesn't the MS install do that already?
Add Microsoft Visual Studio 10.0\Common7\IDE to your path, and this issue will not exist any more. You will be able to build without running this silly batch file every time.
I noticed when I installed Microsoft Visual Studio 2010 Express that under the "Microsoft Visual Studio 2010 Express" folder in the Start Menu, there is a link to "Visual Studio Command Prompt (2010)", which sets up all the necessary environment variables when opened. That way you shouldn't have to edit you PATH variable.
This shortcut runs the following:
%comspec% /k ""C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
If it's not convenient to use the shortcut, perhaps you could learn something of use from investigating what this .bat file does?
I met same error,it is because we installed a vs2010 x86 version to a x64 system...
Open two folders:
C:\Windows\Microsoft.NET\Framework\v4.0.30319
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin
You will find two cvtres.exe. Righ click, select Properties, then Details. Delete the older version, and cmake will work well.
I hope this may help you.
Thanks to "zhoudongao" # http://bbs.csdn.net/topics/390121452?page=1#post-394768226.
I know this is a bit dated but if anyone's looking for a way to get compiler running from command line; here's what I did to get it running.
I'm using Win7 32bit and Visual Studio 2010. I created a small batch file in C:\Windows. open cmd prompt at C:\Windows as admin, then type the following:
copy con cl.bat
#"C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32" %1 %2 %3 %4 %5 %6
#"C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\cl" %1 %2 %3 %4 %5 %6
then press f6 and hit enter again.
Obviously the path you will use is the install path to where you installed Visual Studio.
You now have working command line compiler from any location or directory in windows. To test this go to desktop and open cmd prompt as admin; I prefer to use Ctrl+Shift and right click then choose open command prompt here.
At command prompt type "cl" (without quotes) and hit enter. you will see a message "Setting enviroment for using Microsoft Visual Studio 2010 x86 tools"
type "cl" and hit enter again and you will get your compiler info. you're all set to compile.
enjoy!
Maybe it will help somebody...
I solved this problem by adding
PATH += %PATH_TO_VS_IN_YOUR_SYSTEM%/Common7/IDE;
to nvcc.profile.
Of course, %PATH_TO_VS_IN_YOUR_SYSTEM% is actual path to Visual Studio in your system.
Old, but maybe still valid:
For me "C:\Windows\System32" somehow got missing from the PATH variable.
Adding the missing folder to the path solved this error. See also VS2010 command prompt gives error : Cannot determine the location of the VS Common Tools folder
if you try to run the tools from the windows cmd.exe directly then you need to set the environments by running the vcvars32.bat file which will set the environment for you. instead you can run the visual studio command prompt which will run vcvars32.bat automatically. if you still have the problem then it's definitely the famous path variable problem.
make sure the "path" variable in the environment has the "c:\windows\system32\" value added to it , because the .bat file will need it to configure the VC tools.
this problem and the like usually happen because of installing many development platforms on the machine which might probably change the path variable.
check this..
https://schrievkrom.wordpress.com/2011/01/25/error-cannot-determine-the-location-of-the-vs-common-tools-folder/

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