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

5

14

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?

Houppelande answered 13/1, 2011 at 5:22 Comment(1)
Possible duplicate of What does "exited with code 9009" mean during this build?Galactose
S
19

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.

Succinic answered 1/2, 2011 at 17:13 Comment(0)
J
10

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"
Java answered 16/2, 2012 at 19:5 Comment(2)
This answer is a lot better than the more upvoted, approved answer. Not all "File not found" errors are quote related. Thank you for the answer.Archy
Also make sure the user running the build has access to the file system locationPhotokinesis
F
1

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.

Friedcake answered 19/1, 2011 at 11:51 Comment(0)
N
1

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"
Narvik answered 21/6, 2016 at 3:20 Comment(3)
My PC has no such environment variable definedAbukir
@DaveInCaz others have also reported the missing envar. For my answer, I was referring to a Windows 7 workstation that was put into service about 6 years ago. I don't recall how the envar was setup.Narvik
While I didn't have that particular environment variable, I agree that I had also assumed you could use mt.exe in the post-build events based on this article: msdn.microsoft.com/en-us/library/bb756929.aspxValente
W
0

The post build script in Visual Studio executes with the default path settings for the machine, not the settings used in the VS Developer prompt. Insert the following line at the beginning of the post build script text box to initialize the VS Dev Prompt environment:

call "$(DevEnvDir)..\Tools\vsdevcmd.bat"

Afterwards tools like MT.EXE can be used without specifying a path, such as:

call "$(DevEnvDir)..\Tools\vsdevcmd.bat"
mt.exe -manifest "$(ProjectDir)$(TargetName).exe.manifest" -updateresource:"$(TargetDir)$(TargetName).exe;#1"
Ware answered 4/7, 2023 at 8:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.