2012-05-25 65 views
8

Powershell初學者在這裏..Powershell編輯Xml導致Visual Studio報告不一致行結束

所以我創建了一個包含PowerShell腳本的Nuget包。 PowerShell腳本在安裝時會修改Visual Studio項目中的xml模式。問題是....

如果有XML文件裏面像

<!--<foo> 
    <bar> 
    </bar> 
</foo>--> 

腳本後多行塊註釋運行Visual Studio會彈出一個消息,說我的文件有「結尾不一致線......」

如果沒有評論,或者如果有喜歡的

<!--foo--> 

單行註釋是沒有問題的。以某種方式,在塊註釋結束的行從CRLF更改爲PowerShell功能的其他內容。

這是保存在XML文件

[xml]$xml = gc $xmlFileLocation -encoding utf8 

$xml.Save($xmlFileLocation) 

我也試着沿

set-content -encoding utf8 $xmlFileLocation $xml.outerXml 

行的東西,但是我不斷收到此消息加載我的PowerShell腳本和...

任何sugguests /幫助將不勝感激。

+0

我不知道是否http://stackoverflow.com/a/6073198/8446可能有幫助嗎? –

回答

7

Get-Content通過Out-String

[xml] $xml = Get-Content 'foo.xml' | Out-String 
$xml.foo.bar = 'baz' 
$xml.Save('foo.xml') 

我只是測試這一點:沒有Out-String,我看到在Visual Studio中的消息。有Out-String,我不這樣做,而且留下評論。

+0

感謝您的解決方法 – rom99