Microsoft Visual Studio 2010 doesn't put build tools in PATH for clean target?

Max DeLiso picture Max DeLiso · Oct 23, 2012 · Viewed 7.9k times · Source

I've configured Microsoft Visual Studio to use a Makefile configuration type, and I've written a makefile to build my project using the Microsoft tools. Under the NMake section of the project configuration I've set the build commandline to be build.bat, which is a file which simply invokes nmake with my makefile as command line argument, like so:

nmake /nologo /f makefile.x86.winnt.msvc2010

This works just fine.

For cleaning, I wrote a target in my makefile which deletes all the build artifacts. It looks like this:

#... the rest of the makefile
clean:
    @erase /f /q $(OBJS) $(OUT) $(MAPFILE) $(PDBFILE)
    @echo + clean

So I set the clean command line to be an nmake invocation with clean as an argument. Like this:

nmake /nologo /f makefile.x86.winnt.msvc2010 clean

I placed this text into clean.bat and set it as the "Clean Command Line," but it doesn't work because the invoking shell cannot locate nmake. I checked the path at the time of the clean invocation and MSVS doesn't include the build tools in the path (including nmake) for cleans. (Note that running the above nmake command succeeds from a shell which has nmake in the PATH).

How can I get MSVS to include the build tools in the PATH so I can invoke nmake in the clean command line? Or is there a better solution?

Answer

Dan picture Dan · Nov 6, 2012

Quoting from the Visual Studio Express Readme:

2. Known Issues

2.4. Product Issues

2.4.1. General Issues (Product)

2.4.1.14. Clean Solution does not work for Configuration Type: Makefile (2010 RC)

Doing "Clean Solution" on an nmake solution reports the following error:

1>------ Clean started: Project: makefiletest, Configuration: Debug Win32 ------
1>  'nmake' is not recognized as an internal or external command,
1>  operable program or batch file.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(33,5):
  error MSB3073: The command "nmake /?" exited with code 9009.
================= Clean: 0 succeeded, 1 failed, 0 skipped ==========

To resolve this issue:

  1. Open the Visual Studio Command Prompt window.
  2. Open Devenv by typing devenv /useenv.
  3. Now "Clean Solution" should work.

Or:

Pass a batch file to the clean command. In the batch file, set up PATH to the nmake tool as well as the other build environment.