Hi all,
First of all, apologies if this is the wrong group - the problem I'm experiencing seems to be in the MSBuild hosted in the VS IDE, rather than the command-line MSBuild.
I have vcproj files with conditional imports (to pull in MSBee build rules for a FX1.1 build). These build fine from the command line with the relevant conditional parameters set - I use a condition of: Condition=" '$(Platform)' == 'Win32 (.NET 1.1)'" so I can in theory use the platform in the IDE to discriminate between 2.0 and 1.1 builds.
This works fine in the IDE for conditional compilation settings (e.g. I have a <DefineConstants>$(DefineConstants);NET11</DefineConstants> in a conditional <PropertyGroup> and that works just fine. However, the <Import> I have to pull in the rest of the MSBuild rules doesn't get parsed. In fact, I can type a non-present filename into the Import directive and the IDE doesn't spot it.
As I say, the command-line works fine, and previous strategies for building 1.1 (based on the Interscape guys' work) which just use conditional blocks also work fine; but trying to use MSBee's target files unmolested requires conditional importing of the targets.
Is this a known issue - I couldn't find any mention of this anywhere - and if so, is there any way around it My only remaining thoughts are to hack the MSBee target files to use conditional tags throughout, but this is pretty ugly.
Any comments appreciated.
Matt

MSBuild conditional import and Visual Studio IDE
orangina
I think your problem is occurring because your conditional is initially being evaluated using the configuration and platform default values set when the project is loaded and when you do change the platform inside of visual studio the import conditional is not being re-evaluated and the import is skipped.
The problem with conditional imports being missed related to how the build files are loaded and evaluated in visual studio. When visual studio loads a project file it evaluates the xml (including imports), properties and items.
When the project is first loaded there are some conditions to set the values for Configuration and Platform (As can be found at the top of the csproject file).
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Any condition on the import tag will be evaluated using (Configuration == Debug and Platform == AnyCPU) or what ever your defaults are.
After visual studio loads the project and changes are made which require a re-evaluation of conditionals in the project file, such as changing the platform, visual studio will re-evaluate the conditions on properties and items but NOT on imports. In general imports are not re-evaluated in visual studio for a couple of reasons. One of those reasons being the performance of reloading and evaluating the xml which would be required for conditionals on imports.
This means that you will need to place conditionals in the MSBee targets files or place code in conditional blocks such as a choose block.
gman
James Talon
Craig, I have acctually a solution for this and I've written an additional script on top of MSBee that fix so you can build from inside of VS. If you are interested in this script, please email me at m4(at)creuna.se
Holo
So, in the short term, there's no quick fix for this short of going in and modifying the MSBee XML files to be conditional.
Thanks for taking the time to clear this up.
Glyn123
Matt,
I'm a bit confused: did you mean to say you're suing this with a .csproj instead of .vcproj .vcproj is native C++ files, and those aren't handled by MSBuild.
What does your import line look line
Neil
Meghavi
I'll make a suggestion to the documentation guys that the import page be updated with this restriction noted.
Thanks.
Pawan Jain
I have a file called CSharp1_1.targets which looks like:
<!--
Build settings for ProFactor C# projects working for FX1.1 builds
-->
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="MSBuildExtras.FX1_1.CSharp.targets" />
<PropertyGroup>
<DefineConstants>$(DefineConstants);NET11</DefineConstants>
</PropertyGroup>
</Project>
This is included from the main csproj thusly:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\VisualStudioSupport\CSharp1_1.targets" Condition=" '$(Platform)' == 'Win32 (.NET 1.1)'" />
<Import Project="..\VisualStudioSupport\VSReferences.xml" />
Inside VS I have the two platforms set up as "Win32 (.NET 1.1)" and "Win32 (.NET 2.0)". Regardless which I select I get a 2.0 build. From the command line:
c:\> msbuild IMVSAddIn.csproj "/p:Platform=Win32 (.NET 1.1)"
builds the 1.1 just fine.
If I move the <PropertyGroup> out of the CSharp1_1.targets file, directly into the .vcproj filem and make that conditional e.g.:
<PropertyGroup Condition=" '$(Platform)' == 'Win32 (.NET 1.1)'" >
<DefineConstants>$(DefineConstants);NET11</DefineConstants>
</PropertyGroup>
then in the IDE if I choose a 1.1 build I can see that the 'NET11' constant has been defined - so I know the IDE sets the Platform appropriately - it just doesn't seem to follow the <Import> directives.
Sorry for the slew of information; I hope that makes sense - and sorry for mixing up my vcprojs and csprojs in my first post!
Thanks for the reply,
Matt
TurgidGrandad
You won't find any references to MSBee in the MSDN MSBuild documentation since MSBee is being developed by the Developer Solutions group, which is part of the DDCPX team at Microsoft. MSBee documentation is provided in the included ReadMe; additional information can be found in our team members' blogs and in our MSDN forum.
The limitation for IDE support comes from the use of Condition=" '$(BuildingInsideVisualStudio)' == ''..." in the <Import Project> tag; see section 4.2.1 of the MSBee ReadMe for an example. This prevents the import from working when building inside Visual Studio. However, even if you remove this condition, you're not home free. The goal of MSBee is to enable MSBuild to build .NET 1.1 assemblies developed in VS 2003. We are not trying to build .NET 1.1 assemblies in the VS 2005 IDE. Consequently, we haven't tested it. I've tried it a couple times and believe that you'll never get a truly integrated IDE experience; the background compiler is always the .NET 2.0 version (meaning Intellisense is tied to 2.0). Additionally, since the VS 2005 IDE assumes that it only builds .NET 2.0 assemblies, there are other built-in limitations. When MSBee is released as shared source (coming in May), we anticipate that developers will try to add some IDE integration.