Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 320
user1934212 Avatar asked May 22 '17 11:05

user1934212


1 Answers

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)

like image 103
ErrCode Avatar answered Oct 15 '22 00:10

ErrCode