[Bug]: Inconsistent behavior when using Choose element for conditional package references in MSBuild #10149
Labels
Area: Language
Issues impacting the MSBuild programming language.
backlog
Documentation
Priority:2
Work that is important, but not critical for the release
triaged
Issue Description
There is an observed inconsistency in MSBuild when attempting to conditionally include NuGet package references using the
Choose
element with theWhen
condition. Specifically, usingChoose
for this purpose does not work as expected, whereas using theCondition
attribute directly onItemGroup
functions correctly.Steps to Reproduce
Create a new .NET project.
Create a Directory.Build.props file in the root directory.
Add the following content to the Directory.Build.props file using the
Choose
element:IsTestProject
property to true in its .csproj file:Run
dotnet restore
and observe that the xunit package is not included.Modify the Directory.Build.props to use the
Condition
attribute directly onItemGroup
:dotnet restore
again and observe that the xunit package is now included.Expected Behavior
Both the
Choose
element withWhen
conditions and theCondition
attribute onItemGroup
should enable or disable the inclusion of NuGet package references based on the specified condition.Actual Behavior
Choose
element withWhen
condition does not reliably include the specified NuGet package reference when the condition evaluates totrue
.Condition
attribute directly onItemGroup
successfully includes the specified NuGet package reference when the condition evaluates totrue
.Analysis
No response
Versions & Configurations
17.9.8.16306
The text was updated successfully, but these errors were encountered: