13

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?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Anand
  • 4,523
  • 10
  • 47
  • 72
  • Possible duplicate of [What does "exited with code 9009" mean during this build?](http://stackoverflow.com/questions/1351830/what-does-exited-with-code-9009-mean-during-this-build) – Michael Freidgeim Mar 17 '16 at 06:09

5 Answers5

18

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.

Jeroen
  • 60,696
  • 40
  • 206
  • 339
jqa
  • 1,340
  • 6
  • 17
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"
Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Nathan Wheeler
  • 5,896
  • 2
  • 29
  • 48
  • 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. – Russell Steen Aug 28 '13 at 18:34
  • 1
    Also make sure the user running the build has access to the file system location – PW Kad Mar 19 '14 at 15:51
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"
Community
  • 1
  • 1
bvj
  • 3,294
  • 31
  • 30
  • My PC has no such environment variable defined – StayOnTarget Sep 08 '17 at 11:44
  • @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. – bvj Sep 09 '17 at 01:35
  • 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: https://msdn.microsoft.com/en-us/library/bb756929.aspx – Rachel Martin Oct 15 '18 at 13:53
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.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
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"