1

I have a situation similar to the following:

A solution with two projects, A and B, with A referencing B. In addition to the standard build configs, Debug and Release, I would like to add a third Staging, which lets me do some config transforms for project A only. The Staging build config would have no effect on B and so I don't add it to the project.

Using the solution configuration manager, it's easy to set this scenario up...when the Active Configuration is Staging, A will use Staging and B will use Debug. The solution builds as expected. However, running

msbuild A.csproj /p:Configuration=Staging

will fail with The OutputPath property is not set for project B since B does not have the Staging build config.

My question is if there is a simple way to avoid this when building the project via msbuild

Adding the Staging config to B would work, but it seems cleaner to only add build configs to the projects they affect, and leave the rest alone. In a solution with many projects, ensuring every project has all of the possible build configs is not ideal (though not exactly terrible, either).

Bort
  • 7,398
  • 3
  • 33
  • 48

1 Answers1

0

In the A.csproj file add the following lines

  <ItemGroup>
    <ConfigList Condition=" '@(ConfigList)' == '' and $(Config) != '' " Include="$(Config.Split('+'))" />
    <!-- parse all requested configurations into a list -->
    <ConfigList Condition=" '@(ConfigList)' == '' " Include="Debug" />
    <!-- if no configurations were specified, default to Debug -->
  </ItemGroup>

And add a target for the referenced project in A.csproj

  <Target Name="Build">
    <MSBuild Projects="$(MSBuildProjectDirectory)\..\B\B.csproj" Properties="Configuration=%(ConfigList.Identity);OutputPath=$(MSBuildProjectDirectory)\bin\%(ConfigList.Identity)" Targets="Build" />
  </Target>

When you build the project A, using /p:Configuration=Staging, the target to the referenced project will pass the configuration along and create the output directory required.

Look at this post, it gives a clear description of what you are trying to do.

Community
  • 1
  • 1
CheGueVerra
  • 7,849
  • 4
  • 37
  • 49