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

2.4k Views Asked by At

My msbuild definition looks like this:

<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>

Where several irrelevant lines have been left out, to focus on the relevant entries.

I verified that 'MSBuild.Community.Tasks.Targets' exist at the MSBuildCommunityTasksPath, but when I generate the build target, I get

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

What could be the problem?

1

There are 1 best solutions below

0
On

Probably too late to help OP, but recently had the same problem and it seems that by defining these two properties it started working: MSBuildCommunityTasksPath and MSBuildCommunityTasksLib.

So something like this should work:

  <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>

The use of the Condition attribute will help avoid collisions (e.g. if you have more than one target file that defines those properties)