I'd like to contribute to MSBuild a task we wrote for aspnet that I think would be generally useful. Is this something MSBuild would accept as a PR?
GenerateFileFromTemplate
Purpose: pre-process a source file using MSBuild variables.
Usage:
<GenerateFileFromTemplate
TemplateFile="MyFile.cs.in"
OutputPath="$(IntermediateOutputPath)MyFile.cs"
Properties="ClassName=Banana;Method=Abc" />
Template file example
// MyFile.cs.in
public class ${ClassName}
{
public void Method${MethodName}()
{
Console.WriteLine("`${NotReplacedDueToBacktick}"");
}
}
Template syntax:
- variables in the template file use powershell/bash syntax:
${VarName}.
- if you need a file with
${...}, you can escape this with a backtick: `${...}
Justification:
WriteLinesToFile is good, but I've frequently run into problems with it when I need to write a file that has \, /, or ; in it.
Current implementation: https://github.com/aspnet/BuildTools/blob/master/modules/BuildTools.Tasks/GenerateFileFromTemplate.cs, https://github.com/aspnet/BuildTools/blob/master/test/BuildTools.Tasks.Tests/GenerateFileFromTemplateTests.cs
cc @jeffkl @livarcocc
I'd like to contribute to MSBuild a task we wrote for aspnet that I think would be generally useful. Is this something MSBuild would accept as a PR?
GenerateFileFromTemplate
Purpose: pre-process a source file using MSBuild variables.
Usage:
Template file example
Template syntax:
${VarName}.${...}, you can escape this with a backtick:`${...}Justification:
WriteLinesToFile is good, but I've frequently run into problems with it when I need to write a file that has
\,/, or;in it.Current implementation: https://github.com/aspnet/BuildTools/blob/master/modules/BuildTools.Tasks/GenerateFileFromTemplate.cs, https://github.com/aspnet/BuildTools/blob/master/test/BuildTools.Tasks.Tests/GenerateFileFromTemplateTests.cs
cc @jeffkl @livarcocc