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.

[Bug]: Condition attribute is ignored in legacy csproj files when referenced from an SDK csproj file

See original GitHub issue

Issue Description

When an SDK style csproj file references an legacy csproj file, that references other projects conditionally based on the build target, the condition in the legacy project file is ignored.

When the SDK style project file is backported to an legacy csproj file format, the build works fine.

Steps to Reproduce

Sdk.csproj

<Project Sdk="Microsoft.NET.Sdk">
<!-- ... -->
<ItemGroup>
    <ProjectReference Include="..\Legacy\Legacy.csproj" />
  </ItemGroup>
</Project>

Legacy.csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- ... -->
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'False|False' ">
    <ProjectReference Include="..\Legacy2\Legacy2.csproj"  Condition=" '$(Configuration)|$(Platform)' == 'False|False' " />
  </ItemGroup>
</Project>

Expected Behavior

The Condition attribute should be honored.

Actual Behavior

The condition is ignored and the build breaks because it can’t build the Legacy2 project.

Analysis

Our current workaround is to use legacy .csproj file format only.

Versions & Configurations

MSBuild version 17.6.3+07e294721 for .NET Framework 17.6.3.22601

Visual Studio Version 17.6.3

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
AR-Maycommented, Jun 20, 2023

Team Triage: @JaynieBai, could you please reproduce it and collect binlog (a binlog with expected behavior would be helpful as well)?

0reactions
JaynieBaicommented, Jul 12, 2023

It’s the build that makes problems.

The build has problems since condition is not respected in VS when NuGet Restore https://github.com/NuGet/Home/issues/12729#issue-1790050248

Read more comments on GitHub >

github_iconTop Results From Across the Web

MSBuild reference for .NET SDK projects
Reference for the MSBuild properties and items that are understood ... This property is ignored if TargetFramework (singular) is specified.
Read more >
PackageReference condition is ignored for old project format
I don't believe non-SDK projects support PackageReference ; I suspect they are being ignored regardless of any condition you specify.
Read more >
Old csproj to new csproj: Visual Studio 2017 upgrade guide
NET Core went from the project.json to csproj file format, and the new csproj format is leaner, easier to read, and adds new...
Read more >
Moving to SDK-Style projects and package references in ...
The test project uses the packages NUnit and the NUnit3TestAdapter. Both are installed using the legacy nuget package format (!). The new SDK...
Read more >
Ignore Specific files for a target framework on C# | Medium
I wanted to ignore some .cs file when I compile net461 binary. Compile item doesn't work. My colleague told me about the solution....
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