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

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"

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.

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.

Running vcvars32.bat before compiling in Code::Blocks?

I've installed Visual Studio C++ Express 2012 and want to use it's compiler with Code::Blocks. Starting cl.exe does not work (missing mspdb100.dll) until I run vcvars32.bat, but that does only hold on for the current session in the Command-line. The same applies to compiling with Code::Blocks.
How can I make it run the vcvars32.bat before compiling?
Workaround
That workaround is actually not what I was looking for, but it works, and that is important. Instead of letting Code::Blocks running cl.exe directly, I've set-up a simple batch-script that runs vcvars32.bat before running the actual compiler.
REM File: cl.bat
call vcvars32.bat
call cl.exe %1 %*
In the project properties, you have a section Build events. You can add vcvars32.bat to the pre-build event.
To run the .bat before compiling in Code Blocks(16.01), go to the project build options and its under the "pre/post build steps" tab. This tab only appears in the project settings, not the compiler settings.
However, adding "vcvars32.bat" (or "vcvars64.bat") to the pre build steps didn't fix the error for me.
I found the directory where the library is and added it to the linker search directories. This gave errors about further missing libraries. I added the following paths to my linker settings. These will almost certainly be different for you. I'm installed MSVS 2017 community edition. For some reason known only to Microsoft, the necessary libraries are installed on two different drives.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\lib\x64
D:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\um\x64
D:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x64
Note that the .bat script is no longer necessary if you add these paths by hand.

Resources