6

I have added the command BuildOnlyProject to the Menu. But it is always disabled. It is also disabled, when I select a Project-Node in the Solutionexplorer. Does someone know why?

Thanks and best regards, Thomas

BennoDual
  • 5,865
  • 15
  • 67
  • 153
  • What about when selecting a sub-node of the project? Does the option appear in the context menu of the project? does it work properly? – shoosh Apr 22 '11 at 00:38

4 Answers4

6

Visual Studio does not support project only builds for C# or Visual Basic projects, only for C++ projects. If you have a mixed solution with both C# and C++ projects in it you can select a C++ project in the Solution Explorer and you will see:

  • Build -> Project Only -> Build Only CPlusPlusProjectName

in the menu. Using this menu option will literally cause just a single project to be built as demonstrated by the output window. On the other hand, if you select a C# project, the "Project Only" sub-menu will be gone and the only way to build the project will be with:

  • Build -> Build CSharpProjectName

When you use this menu option the selected project and any other projects that the project depends on will also be built, often several projects in all.

This is why if you select a project that is not a C++ project the "Build Only Project" command will be disabled.

Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
  • ok - and there is now way to define in c#, that only the Current Project should be build - without the projects, which depends on the current? – BennoDual Apr 22 '11 at 12:37
  • As much as we might like to have that feature, Visual Studio does not have it. But "Build -> Build ProjectName" at least doesn't build other projects that don't depend on ProjectName so it is still faster that building the solution. – Rick Sladkey Apr 22 '11 at 15:51
  • Is there possibly a way to do this directly with MSBuild? - So I can write a script to reach my goal. – BennoDual Apr 23 '11 at 20:10
  • That comes with its own set of problems but if it works in your situation, then yes. – Rick Sladkey Apr 23 '11 at 20:24
  • Would it be possible to get a sample, how I can do this with MSBuild? – BennoDual Apr 25 '11 at 09:30
  • 1
    I think a better approach is to use the Configuration Manager. Create a "Debug - MyProject Only" configuration and only select your project to build in that configuration. Then you can use Ctrl+Shift+B to build the solution and it will only build your project. To really build the solution go back to "Debug" or another configuration. – Rick Sladkey Apr 27 '11 at 06:22
4

Do you want anything to happen that would be different from the command Build.BuildSelection? It seems that Build.BuildProjectOnly does not work, and MS seems to imply that what people want is Build.BuildSelection.

Community
  • 1
  • 1
Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
  • I came here looking for a way to do what F5 does: build *only* the current project (leaving dependencies alone), and *only* if it's out-of-date. `BuildSelection` goes through all dependencies and the current project, even if not out of date. – Roman Starkov Jun 12 '12 at 18:42
2

If you want to get dirty why not add a special build configuration to your project which only includes the one project you want to build

Project configuration

only the selected projects will be build.

Martin
  • 1,028
  • 17
  • 23
1

MSBuild checks for a property called BuildProjectReferences. So if you're running MSBuild manually, you can issue:

MSBuild.exe My.Project.csproj /p:BuildProjectReferences=false
Community
  • 1
  • 1
Tom Mayfield
  • 6,235
  • 2
  • 32
  • 43