How do I import the msbuildcommunitytasks project from another msbuild project with a relative file path?

Noel Kennedy picture Noel Kennedy · Jan 22, 2010 · Viewed 11.8k times · Source

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.

Answer

Sayed Ibrahim Hashimi picture Sayed Ibrahim Hashimi · Jan 22, 2010

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:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildCommunityTasksLib Condition="'$(MSBuildCommunityTasksLib)' == ''">E:\Data\Development\My Code\Community\MSBuild\CommunityTasks\</MSBuildCommunityTasksLib>
  </PropertyGroup>

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

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

</Project>