Conditional Import MSBuild

Is there a workaround for conditional imports in MSBuild?

I found evidence here and here is the detailed error information in the MSBuild IDE interface. In particular, statements are Importnot reloaded upon creation:

This is a known limitation. VS will process tags only once when the project is loaded. So any tag is active at the time of loading the project (based on any values ​​that you had at the moment) ... what is the tag that you get for the life of this project in the IDE

For example, I might need to import a project, baror bazbased on a value foo:

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

Is there a workaround or other approach that I can use to perform the desired functions?

+1
source share
2 answers

I do not think that you can overcome this using the conditional import mechanism. What are you really trying to accomplish?

Said Ibrahim Hashimi

My book: Inside Microsoft Build Engine: Using MSBuild and Team Foundation Build

+1
source

It depends on what is in your goal files, but if you just set the properties based on the $ (foo) property, you can use the pre-build event or the prefix target to do the same job.

0
source

Source: https://habr.com/ru/post/1713763/


All Articles