Take the 2-minute tour ×

Please go easy I am new to msbuild and msbuildtasks!

How can I set a property which represents a relative file path to a targets file which I want to import? I need relative references so it will work on all dev machines. But the target for import is trying to use the relative file path internally, which won't work as it is re-evaluated relative to the imported target!

Effectively I am trying to work around the documented behaviour of imported projects:

All relative paths in imported projects are interpreted relative to the directory of the imported project. Therefore, if a project file is imported into several project files in different locations, the relative paths in the imported project file will be interpreted differently for each imported project.

share|improve this question
Is there a specific reason why you don't put the MSBuildCommunityTask lib side by side with MSBuild to %PROGDIR%\MSBuild\MSBuildCommunityTasks\ ? The path could then be relative to MSBuild (like suggested by MSBCT people): <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.‌​Targets"/> –  Filburt Jan 22 '10 at 15:48
Yes, because I would then have to install it on all dev/build machines and then have to manage upgrading them. –  Noel Kennedy Jan 22 '10 at 16:00
add comment

5 Answers

There was a similar question at Is it possible to use MSBuild Extension Pack without installation?. That question was how to do the same with the MSBuild Extension Pack, both of which are similar in this aspect. For the Extension Pack you have to declare the property ExtensionTasksPath,and for the Community tasks you have to declare a similar property named MSBuildCommunityTasksLib. So in your case it should look like:

    <MSBuildCommunityTasksLib Condition="'$(MSBuildCommunityTasksLib)' == ''">E:\Data\Development\My Code\Community\MSBuild\CommunityTasks\</MSBuildCommunityTasksLib>

  <Import Project="$(MSBuildCommunityTasksLib)MSBuild.Community.Tasks.Targets"/>

  <Target Name="Demo">
    <!-- Use the tasks here -->

share|improve this answer
But these are absolute file paths no? Or am I missunderstanding? I need to reference it with a relative file path, or at least to be able to convert the relative file path at runtime. –  Noel Kennedy Jan 22 '10 at 16:18
Most of the tools require a full path to work properly. I've set up a couple of variables in a .proj that I incude in all of my 'working' .proj files. These variables contain the fixed part of paths for various things. In a Property Group: <SolutionRoot>$(WorkingDrive)$(SolutionFolder)\$(Branch)\NET\BuildOut$(Configura‌​tion)</SolutionRoot> $(SolutionFolder) is built from other things, like the Major-Minor build number etc. (Specific to our setup) Then the other .proj files import it: <Import Project="AlliantBuildProperties.proj"/> –  DaveE Jan 22 '10 at 17:07
You should be able to build a full path from relative path. You can use properties like MSBuildProjectDirectory. –  Sayed Ibrahim Hashimi Jan 22 '10 at 19:15
"<MSBuildCommunityTasksLibCondition=" should be "<MSBuildCommunityTasksLib Condition=" –  jaraics Jul 12 '12 at 9:04
Declaring MSBuildCommunityTasksLib might not be enough, see @Vipresh 's answer –  jaraics Jul 12 '12 at 9:44
add comment

@Sayed Ibrahim Hashimi

Talkin about MSBuild4 Just declaring the MSBuildCommunityTasksLib wont suffice cause if u check the MSBuild.Community.Tasks.Targets file the properties are declared as follows

    <MSBuildCommunityTasksPath Condition="'$(MSBuildCommunityTasksPath)' == ''">$(MSBuildExtensionsPath)\MSBuildCommunityTasks</MSBuildCommunityTasksPath>

So if U only over ride the MSBuildCommunityTasksLib it will again get over ridden in the MSBuild.Community.Tasks.Targets file as it is not conditional So u HAVE TO ALSO OVERRIDE MSBuildCommunityTasksPath so that its proerty is NOT SET FROM MSBuildExtensionsPath but from ur custom path. Correst me if I m wrong

share|improve this answer
add comment
up vote 4 down vote accepted

Ok, I've found the answer. Essentially you have to set the property MSBuildCommunityTasksPath as a relative path back to the original containing directory.

For example, given a folder structure like this:

Root---project---Build---{My msbuild project}
           |-Tools---MSBuildCommunityTasks---{Binaries and Targets}
Where :
{My msbuild project} is in Root\Project\Build\
{MSbuildCommunityTasks} is in Root\Project\Tools\MsBuildCommunityTasks

To get the targets project to reference its binaries via the property MSBuildCommunityTasksPath, it will find the tasks file like this:

    <MSBuildCommunityTasksPath>..\MSBuildCommunityTasks\</MSBuildCommunityTasksPath> <!--Relative path back to yourself-->

Then you can import the targets file with another relative file reference :

  <Import Project="..\..\Tools\MSBuildCommunityTasks\MsBuild.Community.Tasks.Targets"/>
share|improve this answer
add comment

This appears to be one answer:


But this (if I understand it correctly) appears to be a ridiculous solution. To get the paths to work I need to change the imported project references? What would happen if I wanted to reference the imported project from third project in another folder?!?

share|improve this answer
add comment

I'm a noob at msbuild if I'm quite honest however I've just solved my own problem I had with this. I was turning one of the targets into its own project and it wasn't finding the paths for the msbuild community paths. If you look at your original project you may find something like this


<Import Project="MSBuildExtensionPack\MSBuild.ExtensionPack.tasks"/>
<Import Project="MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>

Copy this code into your new project and it should work.

share|improve this answer
This cannot work. Your variables are not even escaped using $(). Example: <Import project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets"/> –  Alkaline Dec 19 '12 at 4:15
add comment

Your Answer


