string replace with MSBuild

I started with this project
https://developer.xamarin.com/samples/mac/UseMSBuildToCopyFilesToBundleExample/
that works

I now want to replace text in files like this:

https://msdn.microsoft.com/en-us/library/dd722601.aspx

<UsingTask TaskName="TokenReplace" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
    <ParameterGroup>
        <Path ParameterType="System.String" Required="true" />
        <Token ParameterType="System.String" Required="true" />
        <Replacement ParameterType="System.String" Required="true" />
    </ParameterGroup>
    <Task>
        <Code Type="Fragment" Language="cs"><![CDATA[  

string content = File.ReadAllText(Path);
content = content.Replace(Token, Replacement);
File.WriteAllText(Path, content);

]]>

<TokenReplace Path="C:\Project\Target.config" Token="$MyToken$" Replacement="MyValue" />

I now got this error:

Error MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assembly "/Library/Frameworks/Mono.framework/Versions/5.4.0/lib/mono/msbuild/15.0/bin/Microsoft.Build.Tasks.v14.0.dll". (MSB4175) (UseMSBuildToCopyFilesToBundleExample)

How can I use MSBuild to replace text in files?

Sign In or Register to comment.