I have 2 projects, first project (MyProject.Web) references second. First project has multiple configurations, while second project has only Debug and Release.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;DEV1;DEV2;QA;QA_AUTO</Configurations>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MyProject.Services\MyProject.Services.csproj" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
</Project>
I run msbuild with the following parameters to build first project:
msbuild /p:Configuration=DEV1
How msbuild decides which configuration from second project to use?
What configuration will be selected if I run it with /p:Configuration=UNKNOWN?
When specifying a property on the msbuild
/ dotnet build
command line (-property:Foo=Bar
or short forms), they are trated as global property and thus apply to all projects involved in the build.
This means that in your example, all projects will build with DEV1
set as configuration. Do note that the Configurations
property is merely a hint to IDEs / Tooling on what strings to offer a user.
If you need to reference a specific configuration, you could update the project reference based on the current configuration:
<ItemGroup>
<ProjectReference Include="..\TestClassLib\TestClassLib.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)' != 'Debug'">
<!-- Other configurations reference release version -->
<ProjectReference Update="..\TestClassLib\TestClassLib.csproj" AdditionalProperties="Configuration=Release" />
</ItemGroup>