I came up with a new solution that works both for MSBuild and Visual Studio.
First, BaseProj is set up to build with the location api if the conditional compilation symbol INCLUDE_LOCATION_API
is defined.
Projects A and B is set up to build with a pre-build event that executes a powershell script, pre-build.ps1. (refer to this question).
pre-build.ps1 will read the manifest of the current project to determine whether it has the location capability (ID_CAP_LOCATION
), and if BaseProj Debug and Release configurations defines INCLUDE_LOCATION_API
. If necessary, INCLUDE_LOCATION_API
will be added or removed. Since this will modify the BaseProj.csproj, the build script will exit with an error code to prevent the build from complete.
When I build from VS, if BaseProj has correct configurations, it will build normally. If it has the wrong configuration, BaseProj.csproj will be modified and the build fails, but then the next build will succeed.
In my build script, I execute pre-build.ps1 once before the actual build, ensuring that the project has correct configuration. Then MSBuild is executed and project is built successfully.
I Wouldn't consider this best practice, but it gets the job done and I don't need to think about what configurations should be used when switching between projects.