在 VS2010 中成功构建后,我需要替换缩小的 .js 文件中的简单字符串。
因此,我尝试从“构建后事件”窗口运行一个简单的命令行调用。
这个例子,来自这里:https://blogs.technet.com/b/heyscriptingguy/archive/2008/01/17/how-can-i-use-windows-powershell-to-replace-characters-in-a-text-file.aspx https://blogs.technet.com/b/heyscriptingguy/archive/2008/01/17/how-can-i-use-windows-powershell-to-replace-characters-in-a-text-file.aspx完全操纵生成的 .js 文件。出了问题,我怀疑在我的缩小的 .js 文件中遇到了一些奇怪的字符,从而搞砸了。
(Get-Content C:\Scripts\Test.js) |
Foreach-Object {$_ -replace "// Old JS comment", "// New JS comment"} |
Set-Content C:\Scripts\Test.js
我怎样才能像在unix中一样在一行中完成如此简单的任务..?
很高兴看到 diff 文件。没有更多信息,一些信息:
Edit:
评估字符串时使用双引号。例子:
$r = 'x'
$a = 'test'
'beg',1,2,"3x",'4xfour','last' -replace "1|$r","$a"
gives
beg
test
2
3test
4testfour
anything
要保存没有结束新行的内容,只需使用[io.file]::WriteAllText
$repl = (gc C:\Scripts\Test.js) -replace 'a','b' -join "`r`n"
[io.file]::WriteAllText('c:\scripts\test.js', $repl)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)