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/
Related
Visual Studio 2019, Windows 11. IBM Blockchain Platform Tutorial, A5: Invoking a smart contract from an external application, step A5.26: In the main VS Code menu, click 'Terminal' -> 'Run Build Task...':
I get the error below:
Executing task in folder src: msbuild /property:GenerateFullPaths=true /t:build /consoleloggerparameters:NoSummary
'msbuild' is not recognized as an internal or external command,
operable program or batch file.
The terminal process "C:\WINDOWS\System32\cmd.exe /d /c msbuild /property:GenerateFullPaths=true /t:build /consoleloggerparameters:NoSummary" terminated with exit code: 1.
Every step runs good to this point. VS is updated. Need help. If you offer any advice, please be specific. I am not a programmer or developer, have some experience but not much. I won't know what runs on /PATH/xxx/version...unless you tell me what 'xxx' is. I have written a blockchain (through a tutorial) and got it to run. Thanks. Just trying to learn.
Start VS Code by running code.exe from a Developer Command Prompt for VS 2019 (which is in the the Windows start menu under Visual Studio 2019). That will setup the path correctly to use VS2019 tools, including msbuild. And VS Code will inherit that path so will have access to msbuild.
I am trying to run this command on the picture within the Jenkins builder
However, i get
"tf' is not recognized as an internal or external command,
operable program or batch file."
tf are commands which work within Visual Studio or through the Visual Studio Command prompt tfpt.exe which is why I was trying to set an environment variable..Oh and I can't use the EnvInject Plugin cuz we just don't use it.
The command should be:
SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE;%PATH%
You are missing = after SET PATH, further, your newly added path should point to the folder containing TF.exe and not to TF.exe itself.
This command need a VS or Team Explorer installed. Make sure your Jenkins
build agent have one of them installed.
Besides you are lacking of "=" with set path =
I've attempted to do this both in Visual Studio 2010 and Visual Studio 2012. If my Gruntfile.js file is in the root of my project I can run the "grunt" command from the post build event command line and it runs without a problem.
grunt or grunt.cmd
But if it's in a sub directory
$(ProjectDir)Public\grunt or $(ProjectDir)Public\grunt.cmd
It gives me this error
The command "c:\web\Public\grunt.cmd" exited with code 9009.
I've been researching this but I'm not finding any much help out there. I did find in the grunt documentation that I need to use "grunt.cmd" instead of just calling "grunt" but thats not helping me much.
What's happening is you're specifying an exact path for grunt, which doesn't actually reside at $(ProjectDir)Public\. When you're in that directory on a command prompt and type grunt, it executes because you've set your path environment variable to include the directory where grunt lives.
Luckily the post build commands in VS act like a command window, so you can put this in your post build commands:
CD $(ProjectDir)Public\
grunt
And that should work (assuming a default grunt task is defined).
If you had Visual Studio open and then:
Installed node package manager (npm) and grunt
Then tried to run pre/post build commands including grunt command.
The build will simply fail with the "exited with code 9009" message. (Meaning "I don't know what grunt command is")
To resolve this situation just close visual studio and reopen it (as #longda mentioned on his comment) and everything will work just fine.
I'm using VS 2013 Premium and latest version of npm/grunt.
You can run as post build using task runner as shown below.
Right click on the build --> bindings--> and then specify if you need it to run post or pre build
Somewhat related, I had a weird issue that xcopy would not run after grunt, running them as a single command fixed it:
cd $(SolutionDir)..\App
grunt release && xcopy "$(SolutionDir)..\App\release" "$(TargetDir)Content\" /Y /E /S
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.
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"