MSBuild Conditions and Visual Studio
Don’t trust Visual Studio…
My goal was to include a different file inside my project depending on selected project configuration, something that MSBuild is able to do using an appropriate Condition applied at item level or, in case of multiple items involved, at ItemGroup level.
After adding the two files to my project and customizing their content, I’ve edited the .csproj file and added following statements:
<AppxManifest Include="Package.debug.appxmanifest" Condition="'$(Configuration)'=='Debug'">
<AppxManifest Include="Package.release.appxmanifest" Condition="'$(Configuration)'!='Debug'">
but the result was that inside Visual Studio both files were listed and since the app can’t have more than one .appxmanifest file the project couldn’t build.
Two files aren’t better than one
After several unsuccessful tentative I then tried with another cool way to define non mandatory content inside a .csproj via the Choose element.
<AppxManifest Include="package.debug.appxmanifest" >
<AppxManifest Include="Package.release.appxmanifest" >
but also this alternative apparently was not working and i started getting lost until my friend Damiano hinted me at this old StackOverflow post where it is mentioned that Visual Studio (2010! at that time) doesn’t filter item out based on applied condition. 🙈
So in the end everything was working, just a little ”annoyance” that after several editions of Visual Studio is still there.
I hope in future Visual Studio will dim out project items not satisfying a condition so that it will be immediately evident that that file is not part of the build.