Bug 11766 - Import Condition doesn't work with Exists($(MSBuildExtensionsPath))
Summary: Import Condition doesn't work with Exists($(MSBuildExtensionsPath))
Status: RESOLVED FIXED
Alias: None
Product: Tools
Classification: Mono
Component: xbuild ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-04-12 14:59 UTC by jesse.attas
Modified: 2014-06-19 11:36 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Project and solution which fails to build because of this bug (7.15 KB, application/zip)
2013-04-12 14:59 UTC, jesse.attas
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description jesse.attas 2013-04-12 14:59:51 UTC
Created attachment 3809 [details]
Project and solution which fails to build because of this bug

I'm trying to import a .targets file in my project conditionally depending on whether Xamarin.Android is installed. Here's what I'm trying in my .csproj:

  <Import Project=".\MyTest.targets" Condition="!Exists('$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets')"/>

However in Xamarin Studio on Mac when Xamarin.Android is installed (and presumably the Novell.MonoDroid.CSharp.targets file exists), MyTest.targets is still getting imported. I've verified this by inserting an error in MyTest.targets and noticing that the build fails with that error.

The Condition feature does seem to work in general (I've tried it with some absolute paths). It just seems to break down when I add the MSBuildExtensionsPath variable to my path.

I've attached a sample project that illustrates the issue. This is also reported in the Xamarin forum here:
http://forums.xamarin.com/discussion/3105/weird-behavior-with-msbuild-import-condition/p1
Comment 1 Tom Philpot 2013-12-04 11:08:12 UTC
I ran into this issue with Xamarin Studio 4.2 (our previous version was 4.0.5 which used mdtool by default). 

We have conditions like the following that shouldn't be run on our Mono builds on Mac, but should work when using MSBuild on Windows.

  <Import Project="$(ProjectPath)\..\..\..\tools\SourceAnalysis\StyleCop.Targets" Condition=" '$(Platform)' != 'MacOSX' " />

mdtool simply ignored <Import> elements AFAICT, but xbuild only partially implements them.
Comment 2 Mikayla Hutchinson [MSFT] 2013-12-04 13:53:56 UTC
@Jesse: xbuild special cases the MSBuildExtensionsPath property in the Import element Project attribute so that it represents multiple locations. This special casing is not done for any other elements or attributes.

@Tom: xbuild implements them just fine. Are you certain the Platform property is what you want? It's set by your solution configuration. I imagine what you actually want is "'$(Os)'!='Unix'" (see also bug 15974 comment 1).
Comment 3 Marek Safar 2014-06-19 11:36:19 UTC
Fixed in master