Spook
Spook

Reputation: 25927

How to build project in multiple configurations to automate the build process?

I have a solution, which contains a native project. For the main project to properly work, the following steps should be taken:

  1. The native project has to be built in Release/x86 configuration
  2. The native project has to be built in Release/x64 configuration
  3. All .NET projects have to be built
  4. Both binaries from steps 1 and 2 have to be placed in the main project's output folder.

Is there a way to configure project, so that all of those steps happen upon simply choosing "Build | Rebuild all"? I know of the batch build option, but I'd still have to execute step 4 manually.

Upvotes: 0

Views: 301

Answers (1)

Mr Qian
Mr Qian

Reputation: 23715

I think you have to use msbuild script to build your project rather than VS IDE. Scripts are more flexible and can realize your requirements.

1) create a new file called build.proj and then add these on that file:

<Project>

 <ItemGroup>
    <!--include all c# csproj files to build these projects all at once-->
    <NetProjectFile Include="**\*.csproj" /> 
    <!--include the c++ proj files-->
    <NativeProjectFile Include="**\*.vcxproj" />
 </ItemGroup>
<Target Name="Build">
  <MSBuild Projects="@(NetProjectFile)" Targets="Restore;Build" Properties="Configuration=Debug;Platform=AnyCPU"/>
  
  <!--OutDir is the path of the execute file ,pdb.... if you also want the intermediate files to be in the same folder, you should also use IntDir -->
  <MSBuild Projects="@(NativeProjectFile)" Targets="Build" Properties="Configuration=Release;Platform=x86;OutDir=xxx\xxx\"/>
 
  <MSBuild Projects="@(NativeProjectFile)" Targets="Build" Properties="Configuration=Release;Platform=x64;OutDir=xxx\xxx\"/>

</Target>

</Project>

3) Just run msbuild build.proj -t:Build to get what you want.

Upvotes: 2

Related Questions