[Bug]: Condition attribute is ignored in legacy csproj files when referenced from an SDK csproj file
See original GitHub issueIssue 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:
- Created 3 months ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Team Triage: @JaynieBai, could you please reproduce it and collect binlog (a binlog with expected behavior would be helpful as well)?
The build has problems since condition is not respected in VS when NuGet Restore https://github.com/NuGet/Home/issues/12729#issue-1790050248