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

99封情书 提交于 2019-12-04 17:19:44

问题


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?


回答1:


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.




回答2:


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"



回答3:


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.




回答4:


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"


来源:https://stackoverflow.com/questions/4677055/visual-studio-post-build-event-mt-exe-command-fails-with-code-9009

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!