Here’s nasty little quirk of MSBuild and Visual Studio which took me some time to solve last night…
I have a C# project file which has been modified to import a custom .targets file. This targets file in turn imports some settings (property and item groups) using the following MSBuild statement:
This all works fine when I build using MSBuild from the command line but from within Visual Studio the .items file doesn’t get imported. What’s up with that?!
Turns out that reading the small print for the MSBuild import element tells you why:
While conditional import statements work in command-line MSBuilds, they do not work with MSBuild hosted in the Visual Studio integrated development environment (IDE). Conditional imports are evaluated using the initial configuration and platform default values set when the project is loaded. If changes are subsequently made that require a reevaluation of the conditionals in the project file, such as changing the platform, Visual Studio reevaluates the conditions on properties and items, but not imports. Because the import conditional is not reevaluated, the import is skipped.
removing the Condition attribute fixes the issue!