15
devenv mysolution.sln /build "Release|Win32" /project myproject

When building from the command line, it seems I have the option of doing a /build or /rebuild, but no way of saying I want to do "project only" (i.e. not build or rebuild the specified project's dependencies as well). Does anyone know of a way?

Owen
  • 7,494
  • 10
  • 42
  • 52
  • Possible duplicate of [Build only one project in a solution from command line](https://stackoverflow.com/questions/5558080/build-only-one-project-in-a-solution-from-command-line) – StayOnTarget Jul 07 '17 at 11:47

6 Answers6

21

Depending on the structure of your build system, this may be what you're looking for:

msbuild /p:BuildProjectReferences=false project.proj
Derek Slager
  • 13,619
  • 3
  • 34
  • 34
  • Is the BuildProjectReferences=false going to make a difference when we're only in the context of a project (not solution) file? – Owen Sep 23 '08 at 20:46
  • 1
    Thank you, that worked for me! :) @Owen, yes it does if you have project references in your vcxproj file for example. – Rami A. Dec 29 '11 at 02:02
10

MSBuild is what you want

MSBuild.exe MyProject.proj /t:build
Xian
  • 76,121
  • 12
  • 43
  • 49
3

Don't call devenv, use the genericized build tool instead:

vcbuild subproject.vcproj "release|win32"
Ben Straub
  • 5,675
  • 3
  • 28
  • 43
1

According to MSDN How To: Build Specific Targets in Solutions with MSBuild.exe:

msbuild foo.sln /t:proj1:Rebuild;folder_of_proj2\proj2:Clean
Ilia K.
  • 4,822
  • 2
  • 22
  • 19
0

Thanks for the answers. I see from a bit of looking into msbuild that it can deal with a .sln file rather than a .vcproj; can this be accomplished that way instead of having to know the location of the .vcproj?

Let me take a step back. We have a big solution file and I want a script to do this:

  1. Do a /build on the whole solution.
    (Sometimes some projects fail because devenv doesn't do quite as much building as necessary for the amount of change since the last build.)
  2. For each project that fails, do a /rebuild on it.

When I get to step 2 all I know is the solution filename and the names (not filenames) of the projects that failed. I could easily grep/awk/whatever the .sln file to map from one to the other, but I'm curious if msbuild offers a way to do it directly.

(Ideally I could give msbuild the .sln and the names of all the projects to rebuild in a single command line, as it's a large file and takes a while to load. If that's not possible then the option of manually finding all the project filenames is probably better as loading the solution file every time would be most inefficient.)

Owen
  • 7,494
  • 10
  • 42
  • 52
0

The following works well for building a single C++ project in VS2010:

call "%VS100COMNTOOLS%"\\vsvars32.bat
msbuild /detailedsummary /p:Configuration=Debug /p:Platform=x64 /t:build MY_ABSOLUTE_PATH.vcxproj

Sadly, you can't simply specify a project name and a solution file to build just that project (unless you add a special configuration to your project files perhaps).

Denkkar
  • 5
  • 2
  • 2