无法加载“ MSBuild.Community.Tasks.FileUpdate”任务

use*_*212 5 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>
Run Code Online (Sandbox Code Playgroud)

省略了几行无关的行,以关注相关条目。

我验证了“ MSBuild.Community.Tasks.Targets”位于MSBuildCommunityTasksPath,但是生成生成目标时,我得到了

The "MSBuild.Community.Tasks.FileUpdate" task could not be loaded from the assembly 
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?

Err*_*ode 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>
Run Code Online (Sandbox Code Playgroud)

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