Is it possible to use MSBuild Extension Pack without installation?
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?开发者_Python百科
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.
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.
精彩评论