aboutsummaryrefslogtreecommitdiff
path: root/build_msvc/msbuild/tasks/replaceinfile.targets
blob: 2ccb8b30e053f425e2b590a2ae5ee6d51523a957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask
    TaskName="ReplaceInFile"
    TaskFactory="CodeTaskFactory"
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
    <ParameterGroup>
        <FilePath Required="true" />
        <Replace Required="true" />
        <By Required="false" />
        <ToFullPath Required="false" />
    </ParameterGroup>
    <Task>
      <Using Namespace="System"/>
      <Using Namespace="System.IO"/>
      <Code Type="Fragment" Language="cs">
<![CDATA[
if(File.Exists(FilePath) == false) {
    Log.LogError("replaceinfile task could not locate " + FilePath + ".");
}
else {
    var data = File.ReadAllText(FilePath);
    var by = By;
    if (ToFullPath == "true")
    {
       by = Path.GetFullPath(by);
    }
    data = data.Replace(Replace, by);
    Log.LogMessage("Replace '" + Replace + "' by '" + by + "' in " + FilePath);
    File.WriteAllText(FilePath, data, new System.Text.UTF8Encoding(false));
}
]]>
      </Code>
    </Task>
  </UsingTask>
</Project>