运行 TextTransform.exe 带有来自 Powershell 的参数

Run TextTransform.exe with args from Powershell

我想 运行 TextTransform.exe 在 PowerShell v3 中使用模板上的参数 args。这是我的变量和我尝试过的选项。请注意,它没有“-a”参数,但我需要参数 运行 模板正确。

$textTransformPath = "C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating.0\TextTransform.exe"
$templateath = "$ProjectPath\TheTemplate.tt"
$textTransformParams = "-a !!TheParam!$TheValue"

#& "$textTransformPath" "$templatePath" <-- this runs, but no args!

# these don't work:
& "$textTransformPath" "$templatePath" $textTransformParams
& "$textTransformPath" "$templatePath" "$textTransformParams"

我不知道为什么这么难,看起来应该很容易。如果我在标准命令行中输入它,它就可以工作,这验证了问题出在我的 PS 语法上。

它永远不会失败......在几乎放弃后最后一次搜索找到了答案:

Using $(SolutionDir) when running template via TextTransform.exe

我之前显然没有尝试过的组合是:

& "$textTransformPath" "$templatePath" -a !!TheParam!$TheValue

希望这对其他人有帮助。