Files cannot be conditionally included in a project - by Frank Heimes

Status : 


Sign in
to vote
ID 808120 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 11/8/2013 1:40:13 PM
Access Restriction Public


The example on implies that files can conditionally be included depending on the currently selected configuration.

This does not work as described, though.

The attached project will always include the file "AnyCPU.cs", even if the target platform is changed to x86 or x64. The reason is apparently, that the $(Platform) property gets its default value at the top of the project file and it is only updated to its actual value as selected by the solution configuration after the entire project file has been parsed.

Since conditions on propertygroups (e.g. in line 12 and 13) do work as expected, I consider this a bug.

IMHO, the following construct should also work, but currently doesn't:

    <Compile Include="$(Platform).cs" />	<<< should include x64.cs or x86.cs but not AnyCPU.cs
Sign in to post a comment.
Posted by Microsoft on 12/2/2013 at 3:32 PM
Hello and thank you for this feedback. While MSBuild supports dynamic item lists at build time, Visual Studio does not support constructs such as including wildcard paths or different files based on conditionals. Though we do not plan to add this functionality to Visual Studio 2013, we will consider this feedback when planning for future versions of Visual Studio. Investments in this area will be weighed against the impact of other customer reported issues.
There is a workaround that may help you achieve similar functionality. Instead of placing the condition on the ItemGroup itself, you can try placing it on individual items in the group. In this case, all files will be shown in the solution explorer, but only the platform specific ones will be included in the build. Be aware, however, that this is not fully supported. As a result, doing this might cause some unanticipated behavior in design time features such as IntelliSense and form designers. Rebuilding the project will likely clear up those issues.
Posted by Microsoft on 11/10/2013 at 7:14 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 11/8/2013 at 1:51 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(