powershell - 从 Powershell 运行带参数的 TextTransform.exe

标签 powershell powershell-3.0 t4

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

$textTransformPath = "C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating\14.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

希望这对其他人有帮助。

关于powershell - 从 Powershell 运行带参数的 TextTransform.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40667764/

相关文章:

powershell-3.0 - 根据原始父对象上的数组中对象的属性值过滤原始数组

C# T4 使用 web.config 中的 assemblyBinding/BindingRedirect

asp.net - Entity Framework 5 在保存时停止运行 T4 模板文件

azure - 通过 PowerShell 在消耗计划上创建 Azure 函数失败

windows - 在 Windows 中跟踪滚动日志文件的最有效方法

javascript - 我正在制作一个 Discord 机器人,需要将一些 Powershell 代码翻译成 Javascript

vb.net - PowerShell:禁用Windows.Forms调整大小

powershell - 在 Powershell 中设置像 yyyy-mm-dd 这样的默认日期格式?

powershell - 我可以在 Powershell 中将标题行添加到 CSV 导出吗?

c# - 是否可以在 T4 模板内的 COM 对象上使用后期绑定(bind)?