question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet sln builds using incorrect project configuration for transitive dependencies

See original GitHub issue

Steps to reproduce

mkdir repro &&
cd repro &&
dotnet new classlib -o projA &&
dotnet new classlib -o projB &&
dotnet add projB reference projA &&
dotnet new sln &&
dotnet sln repro.sln add projB &&
dotnet build repro.sln -c Release

Expected behavior

Should build projA and projB using Release configuration.

Actual behavior

projA is built using Debug and projB is built using Release.

$ dotnet build repro.sln -c Release
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for C:\Users\eirik.tsarpalis\devel\private\repro\repro\projB\projB.csproj...
  Restore completed in 52.68 ms for C:\Users\eirik.tsarpalis\devel\private\repro\repro\projA\projA.csproj.
  Restore completed in 210.78 ms for C:\Users\eirik.tsarpalis\devel\private\repro\repro\projB\projB.csproj.
  projA -> C:\Users\eirik.tsarpalis\devel\private\repro\repro\projA\bin\Debug\netstandard2.0\projA.dll
  projB -> C:\Users\eirik.tsarpalis\devel\private\repro\repro\projB\bin\Release\netstandard2.0\projB.dll

The fact that this behaviour is incorrect is corroborated by the fact that project-driven builds do not exhibit this behaviour:

$ dotnet build projB/ -c Release
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 54.32 ms for C:\Users\eirik.tsarpalis\devel\private\repro\repro\projB\projB.csproj.
  Restore completed in 54.32 ms for C:\Users\eirik.tsarpalis\devel\private\repro\repro\projA\projA.csproj.
  projA -> C:\Users\eirik.tsarpalis\devel\private\repro\repro\projA\bin\Release\netstandard2.0\projA.dll
  projB -> C:\Users\eirik.tsarpalis\devel\private\repro\repro\projB\bin\Release\netstandard2.0\projB.dll

Environment data

$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.101
 Commit:    236713b0b7

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.2.101\

Host (useful for support):
  Version: 2.2.0
  Commit:  1249f08fed

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rainersigwaldcommented, Feb 6, 2019

I believe this is a longstanding intentional behavior in solution builds, so I’d be curious to see a case where it works as you expect, @aawadall.

The idea behind the behavior is to allow “solution configurations” that differ from “project configurations”. For example, using the Visual Studio UI, you can configure a solution such that a specific project is built in “Release” configuration even when the solution overall is set to “Debug” (perhaps because Debug builds of that project have bad performance characteristics or something).

To support that, projects don’t directly pass their own configuration down to their dependencies when building in a solution. Instead, they do a lookup inside the solution to see what the corresponding configuration is for the reference, given their own configuration.

When the referenced project is not in the solution, the configuration assignment has a choice: it can either let the current project’s configuration flow as usual (flow if explicitly specified; take default if default is being built) or use the referenced project’s default configuration. The latter is the default, but there’s an explicit control for this–the property ShouldUnsetParentConfigurationAndPlatform. If you want configurations to flow, you must set

<PropertyGroup>
 <ShouldUnsetParentConfigurationAndPlatform>false<ShouldUnsetParentConfigurationAndPlatform>
</PropertyGroup>

in your project(s) (or in a Directory.Build.props for your repo).

0reactions
cataggarcommented, Mar 11, 2022

This bites me every few months. I’d love to see the behavior flipped for net7.

Read more comments on GitHub >

github_iconTop Results From Across the Web

build - Problem referencing transitive dependencies when ...
NET Framework projects from a .NET Core project, and attempting to build them all in one step. The work around required two things:...
Read more >
dotnet build command - .NET CLI
The dotnet build command builds a project and all of its dependencies.
Read more >
dotnet publish command - .NET CLI
dotnet publish compiles the application, reads through its dependencies specified in the project file, and publishes the resulting set of ...
Read more >
Transitive NuGet dependencies: .NET Core's got your back
MSBuild seems to have issues with transitive NuGet dependencies, but after a deep dive into the build logs, it turns out to be...
Read more >
How to diagnose projects load issues in solution? (has errors
We have a solution with 328 projects in it. ... NET.Build.Tasks.ResolvePackageDependencies. b__48_5(String tg). at System.Linq.Enumerable.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found