16

Is there a way to use the MSBuild Extension Pack with a "local" reference that doesn't require you to run the installer? In other words, can you store the targets in a solution items folder so that every developer doesn't have to install it?

Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
Bob
  • 483
  • 5
  • 6

2 Answers2

20

You have to declare the property, ExtensionTasksPath, before the import statment for the tasks. For example take a look at:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ExtensionTasksPath Condition="'$(ExtensionTasksPath)' == ''">E:\Data\Development\My Code\Community\MSBuild\ExtensionPack\</ExtensionTasksPath>
  </PropertyGroup>

  <Import Project="$(ExtensionTasksPath)MSBuild.ExtensionPack.tasks"/>

  <Target Name="Demo">
    <MSBuild.ExtensionPack.FileSystem.File TaskAction="GetTempFileName">
      <Output TaskParameter="Path" PropertyName="TempPath"/>
    </MSBuild.ExtensionPack.FileSystem.File>

    <Message Text="TempPath: $(TempPath)" />
  </Target>

</Project>

The MSBuild Community tasks is similar but the property is named MSBuildCommunityTasksLib. I think for SDC tasks its called TasksPath.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • Thank you! I just watched your DNRtv episodes on MSBuild and they were fantastic. – Bob Nov 22 '09 at 15:10
2

I had trouble getting this to work with relative paths (ie not c:\blah but ..\blah).

This is because you couldn't re-use the ExtensionTasksPath variable if it was relative, since your file (.csproj) and the MsBuild.ExtensionPack.tasks file are in different locations, resulting in a different value for the relative path.

In the end this is what got it working for me (put at top of your .csproj file):

    <PropertyGroup>
   <ExtensionTasksPath Condition="'$(ExtensionTasksPath)' == ''">..\4.0\</ExtensionTasksPath>
  </PropertyGroup>
  <Import Project="..\references\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks"/>

The reason why you need the "..\4.0\" instead of just "" (blank) is because the MsBuild.ExtensionPack.tasks file detects blank and does some different stuff if that is the case. I didn't want to hack the MsBuild.ExtensionPack.tasks file in case I wanted to upgrade it later.

muzzamo
  • 1,721
  • 2
  • 14
  • 18