How to: Use the Same Target in Multiple Project Files

How to: Use the Same Target in Multiple Project Files.

Further to my post yesterday about Importing projects in MSBuild, it’s worth having a quick read over the “Order of Evaluation” section to understand further that it is important where you import a project if you wish to set the properties and items of the imported project.(TL;DR –

  1. Define, in the project file, all properties and items that are used as parameters for properties and items in the imported project.
  2. Import the project.
  3. Define in the project file all properties and items that must override default definitions of properties and items in the imported project.

It’s also important to understand that properties and items names are important as the values shall propagate through the imported projects. So if you have the same key value pair in Project A and Project B, and you import Project A then Project B, the value of Project B will be used when running the targets in Project A. This is because all projects and items are collated prior to the build executing anything. If you’re not careful you may unwittingly update a property/item without even realising that you have done so! I learnt this one the hard way: by hard way I mean 6 hours of looking in the wrong imported project file way!

Author: Richie Lee

Full time computer guy, part time runner. Full time Dad, part time blogger. Knows a thing or two about Pokémon. Knows too much about SQL Agent. Writer of fractured sentences. Maker of the best damn macaroni cheese you've ever tasted.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s