Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run MSBuild, respect the unloaded projects

In Visual Studio, you can unload a project, and when you build the solution (Right-click/build), the unloaded project is not built. However, when you run MSBuild from the command line, like this;

C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe 
  "$slnFile" /t:build /p:Configuration=Debug /verbosity:minimal

the project is built. Is there a way to get MSBuild to respect the projects unloaded in Visual Studio?

The situation is that we have a solution with a number of projects. One of them requires special software to build, and that exists on our build machine but not on all developer machines. This means I can't do a straight command-line build or it fails when it encounters the rogue project.

Any ideas?

[EDIT: MSBuild must be able to do this, because Visual Studio uses MSBuild to do the building. What does VS do that the command line doesn't?]

like image 527
Steve Cooper Avatar asked Nov 24 '10 10:11

Steve Cooper


3 Answers

MSBuild knows nothing about what loaded state the project within a solution are, so what you are trying to do is not possible.

As an alternative, you could define a new build configuration called BUILD_MACHINE (using the Build -> Configuration Manager menu). In this build configuration, enable all of your projects to be built. This is then the configuration that you build on you build machine(s). If you disable the specific project from building in the Debug and Release build configurations (using the same menu options), you can build these configurations on your development machine without having to unload the project you don't want to build.

MSBuild honours build configurations, so you can build your non-build machine build configurations (eg. Debug, Release) using Visual Studio or MSBuild and the troublesome project will not get built.

like image 142
adrianbanks Avatar answered Nov 13 '22 07:11

adrianbanks


A possible solution is to use devenv /build ConfigurationName file.sln instead of MSBuild directly.

However, in your solution, unloading the project is not the right solution to begin with. As people before me have said, use a separate configuration for the build machine.

like image 20
Ilya Avatar answered Nov 13 '22 08:11

Ilya


the information about whether a project is unloaded or not does not go into the sln file, but in the xxx.user file. Hence, MSBuild does not know about it.

Your best bet is to create a simple MSBuild file containing only those projects that can be built everywhere, for example:

<!--build selection of projects-->
<Project
  ToolsVersion="3.5"
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <ItemGroup>
    <DevMachine Include="A\b.vcproj"/>
    <DevMachine Include="B\b.vcproj"/>
    <DevMachine Include="C\c.vcproj"/>
  </ItemGroup>

  <ItemGroup>
    <BuildMachine Include="D\d.vcproj"/>
    <BuildMachine Include="E\e.vcproj"/>
  </ItemGroup>

  <Target Name="All">
    <CallTarget Targets="MakeDevMachine"/>
    <CallTarget Targets="MakeBuildMachine"/>
  </Target>

  <Target Name="MakeDevMachine">
    <VCBuild
      Projects="@(DevMachine)"
    />
  </Target>

  <Target Name="MakeBuildMachine">
    <VCBuild
      Projects="@(BuildMachine)"
    />
  </Target>

</Project>

Only withdrawal is you have to keep it in sync with your solution file.

like image 26
stijn Avatar answered Nov 13 '22 09:11

stijn