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

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.

Related

VS2019 - msbuild is not recognized as internal or external command

I am using VS2019 community and I've set pre-build event:
msbuild "$(ProjectPath)" /t:Clean
I am getting error:
'MSBuild' is not recognized as an internal or external command,
operable program or batch file
How is this possible? Isn't this command supposed to be build into visual studio?
I've checked this and tried to set path environment, but it doesn't help.
Does anybody else has the same problem with this command in VS2019?
Steps that work in my machine:
See this, first we need to make sure MSBuild can be recognized by cmd.exe.
If the command can be recognized by cmd.exe but not build-event from VS, restart the PC can help resolve this issue.
(Something strange is that for my VS still can't recognize it until a restart of the computer)
For VS2019, the correct msbuild path is C:\Program Files (x86)\Microsoft Visual Studio\2019\xxx\MSBuild\Current\Bin
And here's another workaround:
Apart from adding the path of msbuild.exe into Environment Path and call it in pre-build event, you can also consider using MSBuild Task.
Add script below into xx.csproj:(work for .net framework...)
<Target Name="MyCleanBeforeBuild" BeforeTargets="BeforeBuild">
<MSBuild Projects="$(ProjectPath)" Targets="clean"/>
<!--<Message Text="Custom Clean" Importance="high"/>-->
</Target>
With latest update to VS2019 - version 16.3.4 - the error is no longer there.
Using "dotnet" instead of "msbuild" could work if you got that installed.
So, in my case, instead of running "msbuild /t:restore" I figured I can use "dotnet build" and have the same result.
Here's the documentation in case you want to see more equivalent commands.
https://learn.microsoft.com/en-us/dotnet/core/tools/

Visual Studio Code command in Windows not working properly

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.

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.

Run a solution from Visual Studio console without opening the IDE

I am using Visual Studio 2010 SP1.
What I first tried was this:
Open the Visual Studio console tool from start menu
Navigate to project folder (which already contains an executable)
Run: msbuild myproject.sln or msbuild myproject.sln /p:Configuration=Release
This builds successfully, but I can't find an executable to run
The second thing I tried was steps 1 and 2 from above
Running: devenv myproject.sln /Build and devenv myproject.sln /Run
This somewhat works but it seems to open the IDE to run the build
The whole point was to avoid using the ide at all.
Now, how do I build and run a solution without opening the IDE?
--------------------------FIXED------------------------------
The problem was that I was looking in the wrong place for the executable (noob mistake). I ended up using this batch file:
msbuild myproj.sln /p:configuration=Release
cd (("Path to executable" usually in the Debug/Release Folder))
myExecutableName
cd (("Path to original folder"))
Navigate to your solution folder
Run: msbuild myproject.sln /p:Configuration=Release (or Debug)
cd myproject (within your solution folder - it's a sub-folder)
cd bin
cd Release (or Debug)
Run: myproject.exe
You can replace the three separate cd commands with a single one:
cd myproject\bin\Release
Or simply run your executable from the solution folder:
myproject\bin\Release\myproject.exe

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