-1

If I open up Command Prompt, and type msbuild, or /msbuild followed by a path file, It says that

'msbuild' is not recognized as an internal or external command, operable program or batch file.'

However, when I run the same lines in visual studios command prompt it works.. Anybody know why this is?

Here is my python script to run MSBuild through the command prompt

import subprocess
filename="C:\Users\bb\Documents\bb\Code\VisualStudio\tree.ProEAPI.UnitTests\tree.ProEAPI.UnitTests.vbproj"
p = subprocess.Popen(['C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe', filename], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
    print line,
retval = p.wait()
BesaseB
  • 23
  • 2
  • 9
  • Here is a "bat" method. http://stackoverflow.com/questions/5669765/build-visual-studio-project-through-the-command-line/5669820#5669820 – granadaCoder May 15 '13 at 14:38

2 Answers2

5

When you launch a Visual Studio command prompt, it adds some additional locations to the 'path' environment variable - this happens to include the location of MSBuild.

Interesting side note - you can use the 'where' command in batch to find the path of an application. For example, running 'where msbuild' in the Visual Studio command line outputs this:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC>where msbuild
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.NET\Framework64\v3.5\MSBuild.exe

But in the standard command prompt, outputs this:

C:\Users\stephen.edmonds>where msbuild
INFO: Could not find files for the given pattern(s).

You can view the current value of the path environment variable using the command 'set path'

Stephen Edmonds
  • 948
  • 1
  • 9
  • 25
  • When I add the whole filepath to MSBuild.exe directly then add the file path in the command prompt it works. However when i duplicate the same thing into my python script it does not work still it spits out the same message. I'll add an edit of my python code. – BesaseB May 15 '13 at 13:48
1

Because your command pompt is missing the location of the msbuild.exe from its path environmental variable. Usually C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 for .net 4. try setting it in your computer management console or at the command prompt:

set path=%path%;C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\ 

then try msbuild again.

James Woolfenden
  • 6,498
  • 33
  • 53