brad
brad

Reputation: 75454

MSBuild Conditional Imports

Is there a workaround for conditional imports in MSBuild?

I've found evidence here and here detailing a bug in the MSBuild IDE interface. In particular, Import statements do not reload when building:

This is a known limitation. VS will only ever process the tags once, when the project is loaded. So whatever tag is active at the time the project is first loaded (based on whatever values your properties have at that time)... that's the tag that you will get for the lifetime of that project in the IDE

For example, I might want to import the bar or baz project based on the value of foo:

<Import Project="bar.targets" Condition="'$(foo)' == 'bar'" />
<Import Project="baz.targets" Condition="'$(foo)' == 'baz'" />

Is there a workaround or different approach I can use for accomplishing the desired functionality?

Upvotes: 2

Views: 3354

Answers (2)

Sayed Ibrahim Hashimi
Sayed Ibrahim Hashimi

Reputation: 44332

I don't think that you can overcome this using the conditional import mechaism. What are you really trying to accomplish?

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

Upvotes: 0

David McEwing
David McEwing

Reputation: 3340

Depends on what is in your targets files, but if you are just setting properties based on the $(foo) property then you could use a prebuild event, or prebuild target to do the same job.

Upvotes: 0

Related Questions