Visual Studio Code command in Windows not working properly - windows

My question is, how can I make the VS Code command line work properly when manually adding it to PATH on Windows?
Inside of Visual Studio Code, I first tried to install it with the tickbox "install to PATH", but when I typed code in the command prompt, it said command not recognized. So I manually edited PATH and added C:\Program Files (x86)\Microsoft VS Code.
However, when running commands such as:
code -v
the command prompt doesn't print anything, but launches Visual Studio Code instead.

Your path environment variable should include C:\Program Files (x86)\Microsoft VS Code\bin instead of C:\Program Files (x86)\Microsoft VS Code (notice the added \bin at the end).
The bin sub directory provides the batch file code.cmd, that processes the command line before launching code.exe from the parent directory. Going through the batch file is required for the command line to work properly.

Related

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

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

Visual studio 'xsd' command: file path

The command 'xsd' in the Visual Studio (2010) command window is not fiding my file.
Tried full path 'c:\...\etc...', tried path from project folder, tried any sub path of the full path, tried only the file name (as shown on any example in the web of the usage of the tool).
The file is inside the project inside a subfolder, like "project\schema\mySchema.xsd".
Command used
>Tools.Shell xsd <path\>myfile.xsd /classes
returns:
The operation could not be completed. System could not find specified file.
What work around can I make, how should I properly use the tool? (Am I using it wrongly?)
To find XSD.exe these days, go to:
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2
Tools\xsd.exe
Step by step:
Go to C:\Program Files (x86)\Microsoft SDKs\Windows\
Click latest version (e.g. v10.0A)
Click Bin
Select latest .NET Version e.g. NETFX 4.7.2 Tools
There is xsd.exe
When you launch the shortcut that opens the Visual Studio Command Prompt you execute a batch file that set some important string inside the PATH environment variable. These strings contain the folder names where the XSD tool is located.
The shortcuts are located in this folder on my dev PC with Visual Studio 2013
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts
The shortcut that opens the Command Prompt for Visual Studio x86 Native Tools is something like this
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" x86
So, unless your installation is damaged you should be able to find the correct command in the relative directory of your Visual Studio 2010 install.

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...

`msbuild` command not found, but `msbuild.exe` works fine

I run MSys/Bash as distributed in Git for Windows. I added the folder C:\Windows\Microsoft.NET\Framework\v4.0.30319 to my path, so I could run msbuild but it doesn't work
$ msbuild
C:\Program Files (x86)\Git\bin\sh.exe: msbuild: command not found
Yet msbuild.exe does:
$ msbuild.exe
Microsoft (R) Build Engine version 4.0.30319.17929
Yet the command explorer resolves fine. What's going on?
It's a bug in MSys where the same name is shared by a folder and a file (minus the extension). In this case:
File C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Folder C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild
You'll have to workaround by writing msbuild.exe
If the exe file outputs not found, do copy C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe ProjectPath
And then run msbuild.exe
If msbuild.exe cannot be found, it needs to be configured.
Open a command prompt and run the file vsvars32.bat located in your Visual Studio Common7/Tools folder..
i.e C:\Program Files x86\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat
This will correctly setup all the neccessary variables for msbuild.exe to be found.

Visual Studio Post Build Event MT.exe command fails with code 9009

Hi I am running following command from my post build event:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\mt.exe -manifest "$(ProjectDir)$(TargetName).exe.manifest" -updateresource:"$(TargetDir)$(TargetName).exe;#1"
It is failing with Exited with code 9009... I don't understand why this happens; any suggestions?
Try adding quotes around the mt.exe path, e.g.:
"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\mt.exe"
Also, make sure that path is valid.
Hope this helps. I've been beating my head against code 9009 all day and a full quoted path seem to make it work.
Exit code 9009 is a file not found error. The spaces that exist in your path to the post build command cause errors in a command prompt unless you include quotes around the entire path and executable name. Essentially, in your post-build command, it is trying to execute C:\Program with the arguments:
Files\Microsoft
SDKs\Windows\v7.0A\bin\mt.exe
-manifest "$(ProjectDir)$(TargetName).exe.manifest"
-updateresource:"$(TargetDir)$(TargetName).exe;#1"
Since obviously you don't have a file called Program residing in your root directory, this entire command fails. Encapsulating the path and executable in quotes will cause the entire expression to be evaluated as a single command, so everything should work fine if you change the post-build command to:
"C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" -updateresource:"$(TargetDir)$(TargetName).exe;#1"
Or use for VisualStudio x86 in Windows x64
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe"
Here is a potential solution:
You can use the Post build event
functionality of Visual Studio to do
this typing the command above: mt.exe
-manifest app.manifest -outputresource:myapplication.exe;#1. This probably won't work and Visual
Studio will give you an error like
"...exited with code 9009...".
You have to edit the csproj file using
for example the notepad and uncomment
the XML tags related to the Target
Name="AfterBuild" (you can find them
at the end of the file usually). Then,
place the tags related to the
PostBuildEvent within the tags related
to the AfterBuild and then, reload the
project and compile. It will produce a
.exe file that needes to be execute
with Administrator permissions.
Until reading this thread, I foolishly assumed VS would know where mt.exe lives. +1 to #james
Since there's no built-in macro for the current SDK, I relied on the system envar, windowssdkdir
"%windowssdkdir%\bin\mt.exe"

Resources