Powershell beginner here..
So I've created a Nuget package with a powershell script. The powershell script modifies a xml schema inside my Visual Studio project when it gets installed. Problem being....
If there's a multi-line block comment inside the xml file like
<!--<foo>
<bar>
</bar>
</foo>-->
After the script is run Visual Studio pops up a message and says my file has "inconsistent line ending......"
If there is no comment, or if there is a single line comment like
<!--foo-->
There is no problem. Somehow the line ending in the block comment is changed from CRLF to something else by the powershell functions.
This is my powershell script for loading and saving the xml file
[xml]$xml = gc $xmlFileLocation -encoding utf8
$xml.Save($xmlFileLocation)
I've also tried something along the lines of
set-content -encoding utf8 $xmlFileLocation $xml.outerXml
But I keep on getting this message...
Any sugguests/help would be much appreciated.
Pipe Get-Content
through Out-String
:
[xml] $xml = Get-Content 'foo.xml' | Out-String
$xml.foo.bar = 'baz'
$xml.Save('foo.xml')
I just tested this: without Out-String
, I see the message in Visual Studio. With Out-String
, I don't, and comments are left alone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With