Condition on ProjectReference Is Not Respected in Visual Studio
See original GitHub issueIssue moved from microsoft/msbuild#5410
- Please respond to @aolszowka.
From @aolszowka on Friday, June 5, 2020 6:51:14 PM
Steps to reproduce
Here is a repository that reproduces the issue: https://github.com/aolszowka/ProjectReferenceConditionalTest
The jist of it is this project will still show up and build within Visual Studio even when a condition is used in this manner:
<ProjectReference Include="..\A\A.csproj" Condition="'1'=='2'">
<Project>{679190e5-cd34-4391-85de-9031f04f50a5}</Project>
<Name>A</Name>
</ProjectReference>
Calling Pure MSBuild works as expected, should this be a Developer Community Bug?
Expected behavior
Visual Studio and MSBuild should behave identically.
Actual behavior
Visual Studio will attempt to build/reference the project, whereas MSBuild will not.
Environment data
msbuild /version
output:
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
16.6.0.22303
OS info: Windows 10 Enterprise 1909
If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc): Visual Studio 2019 Enterprise 16.6.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ProjectReference in SDK-style project ignores Condition ...
The problem is that I can't build _TestSDK project in a Release configuration in Visual studio 2019 (16.10.2). I got an error
Read more >In VS2017 15.6, build order does not respect references to ...
In newly installed VS2017 15.6, the project references from C# projects (csproj) to C++/CLI projects (vcxproj) in an existing solution are ...
Read more >Conditional Build to use Project reference or Package ...
I have a dependency project called MySDK used in more than one project. MySDK is published as a Nuget package in my Azure...
Read more >Troubleshooting NuGet Package Restore in Visual Studio
This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are...
Read more >Fix intermittent build failures
Learn how to diagnose and fix race conditions in your MSBuild parallel builds.
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
I’ve also hit this on a C++ project (https://github.com/dolphin-emu/dolphin/blob/55c931d6248c6dda5a8a9cbd332131255d62bc3f/Source/Core/DolphinQt/DolphinQt.vcxproj#L524) curious how this:
applies to C++ projects.
Edit: I’m pretty sure this is actually a regression in this case - this vcxproj was working in the past.
Edit2: It actually seems to be some regression with how VS handles the “batch build” and configuration manager UI. For example, if the target Platform is set to ARM64 when VS is launched, VS seems to cache the project reference settings and does not update them, even if a Batch Build targets x64, or if you change the current Platform to x64 in the UI and start a build. So, not sure where this bug should get routed to…however, if there’s a “proper” way to solve it for VS and msbuild (this C++ project’s CI server uses msbuild), it would be great to know. The above-mentioned
<Choose><When>
trick didn’t change the behavior for me.I have the same problem, but moving the conditions to an ItemGroup is not helping. I can build my solution locally in VS, but not with the DotNetCoreCLI or the MSBuild task in Azure DevOps.
Also the project is already using the current project system and if I understand correctly it should not be a problem there?