Open mruiz2112 opened 3 days ago
Are you seeing this in Visual Studio, MSBuild.exe
, or dotnet msbuild
? I remember VS not supporting Condition on ItemGroup, but AFAIK it works fine in command-line builds.
Visual Studio. I haven't tried on MSBuild.exe on dotnet msbuild yet but I can try that and report back with my findings
Seems like the problem is isolated to Visual Studio. I also tested with Jetbrains Rider and didn't run into this issue
https://github.com/dotnet/project-system/issues/1542 looks similar, but it was closed in lieu of https://github.com/dotnet/project-system/issues/2129, which does not mention Condition
.
Issue Description
Adding a condition on an ItemGroup, i.e.
<ItemGroup Condition="false">
, does not work for non-SDK projects. The condition seems to be ignored and whatever is inside the ItemGroup will be added/executed. I've noticed this to be true within a csproj file as well as in a Directory.Packages.props file.My company has a few large non-SDK web apps that we can't upgrade to SDK style so it would be nice to have this fixed.
Steps to Reproduce
WebApplication_NonSDK.zip
I uploaded a small sample solution with an ItemGroup,
<ItemGroup Condition="false">
, that adds a PackageReference. Despite the condition clearly evaluating to false, the PackageReference is added anyway. Changing the syntax to this fixes the issue:However, it is confusing and inconvenient that the conditional on the ItemGroup does not work, especially since it only seems to affect non-SDK projects.
Expected Behavior
The PackageReference is NOT added to the project
Actual Behavior
The PackageReference is added to the project
Analysis
No response
Versions & Configurations
No response