" MSBuild.Community.Tasks.FileUpdate"任务无法加载

时间:2017-05-22 11:12:26

标签: msbuild msbuildcommunitytasks

我的msbuild定义如下所示:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MSBuildCommunityTasksPath>..\..\..\..\_Packages\MSBuildTasks.1.5.0.235\tools</MSBuildCommunityTasksPath>
  </PropertyGroup>
  <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" />
  <Target Name="Build">
    <FileUpdate Files="D:\test.js"
              Regex="(path)+.*?+(\\'.*?\\')"
              ReplacementText="Test" />
  </Target>
</Project>

如果遗漏了几条不相关的行,请关注相关条目。

我验证了&#39; MSBuild.Community.Tasks.Targets&#39;存在于MSBuildCommunityTasksPath,但是当我生成构建目标时,我得到了

The "MSBuild.Community.Tasks.FileUpdate" task could not be loaded from the assembly 

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

为OP提供帮助可能为时已晚,但最近又遇到了同样的问题,并且似乎通过定义这两个属性开始起作用:MSBuildCommunityTasksPathMSBuildCommunityTasksLib

所以这样的事情应该起作用:

  <PropertyGroup>
    <MSBuildCommunityTasksPath Condition=" '$(MSBuildCommunityTasksPath)' == '' ">$(ProjectDir)..\..\MSBuildCommunityTasks</MSBuildCommunityTasksPath>
    <MSBuildCommunityTasksLib Condition=" '$(MSBuildCommunityTasksLib)' == '' ">$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.dll</MSBuildCommunityTasksLib>
  </PropertyGroup>

  <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" />
  <Target Name="Build">
    <FileUpdate Files="D:\test.js"
              Regex="(path)+.*?+(\\'.*?\\')"
              ReplacementText="Test" />
  </Target>

使用Condition属性将有助于避免冲突(例如,如果您有多个定义这些属性的目标文件)