I am trying to add a file "AssemblyInfo.cs" which contain a '' as part of the text.
After Removing the Char RestApi pass
i am using the following code to convert the text to Json - Powershell based
function GetJSContentCS {
param (
$filepath
)
$read = (Get-Content -Encoding UTF8 -RAW -Path $filepath) -replace "(?s)`r`n\s*$"
$jscontent=''
foreach ($item in $read) {
$jsitem = $item '\n'
$jsitem = $jsitem.replace('"','\"')
$jscontent = $jsitem
}
return $jscontent
}
GetJSContentCS -filepath 'C:\temp\AssemblyInfo (2).cs'
Any Advise Would be great
CodePudding user response:
The problem is missing a \
character after c:
in the converted Json.
By running the PowerShell the converted Json is :
[assembly: XmlConfigurator(ConfigFile = @\"c:\appsLogging.xml\", Watch = true)]\n
However, the correct Json should like this:
[assembly: XmlConfigurator(ConfigFile = @\"c:\\appsLogging.xml\", Watch = true)]
Please try the following script to convert the text to Json:
function GetJSContentCS {
param (
$filepath
)
$read = (Get-Content -Encoding UTF8 -RAW -Path $filepath) -replace "(?s)`r`n\s*$"
cls
Write-Host $read
$jscontent=''
foreach ($item in $read) {
$jsitem = $item.replace('"','\"')
$jsitem = $jsitem.replace(':\',':\\')
$jscontent = $jsitem
}
return $jscontent
}
GetJSContentCS -filepath 'C:\temp\AssemblyInfo.cs'
UPDATE: