這個問題在這里已經有了答案: 為什么 Range.BorderAround 向控制臺發出“True”? (1 個回答) 5 天前關閉。
我正在使用 powershell 更新 wpf csproj 檔案中的版本節點。每次我添加版本節點時(當它已經存在時我從來不明白我必須這樣做),突然出現一個屬性串列。
# My Wpf App
Write-Host "WpfApp Versioning started"
$sourceDir = "C:\Users\me\source\repos\mysolution"
$csprojfilename = $sourceDir "\myapp\myapp.csproj"
"Project file to update " $csprojfilename
[xml]$csprojcontents = Get-Content -Path $csprojfilename;
"Current version number is " $csprojcontents.Project.PropertyGroup.Version "."
$oldversionNumber = $csprojcontents.Project.PropertyGroup.Version
# https://gist.github.com/bcnzer/f8d50699c5bf7614923bff733662cb1a
if ($csprojcontents.Project.PropertyGroup.name -notmatch "Version")
{
Write-Host "Version is null."
$csprojcontents.Project.PropertyGroup.AppendChild($csprojcontents.ImportNode(([xml]"<Version/>").DocumentElement,$true))
}
Write-Host "Update Version."
$csprojcontents.SelectNodes("/Project/PropertyGroup/Version")[0].InnerText = [version]($ecatBuildNumber)
Write-Host "Save csproj."
$csprojcontents.Save($csprojfilename)
"Version number has been updated from " $oldversionNumber " to " $ecatBuildNumber "."
Write-Host "WpfApp Versioning Finished"
這是我在使用 Powershell ISE 時得到的輸出。
WpfApp 版本控制開始
更新專案檔案 C:\Users\me\source\repos\mysolution\myapp\myapp.csproj 當前版本號是 6.0.0.6 。版本為空。
名稱:版本 LocalName:版本 NamespaceURI:前綴:NodeType:元素 ParentNode:PropertyGroup OwnerDocument:#document IsEmpty:True 屬性:{} HasAttributes:False SchemaInfo:System.Xml.XmlName InnerXml:InnerText:NextSibling
:PreviousSibling:版本值:ChildNodes {} FirstChild : LastChild : HasChildNodes : False IsReadOnly : False OuterXml : BaseURI
: PreviousText :名稱:版本 LocalName:版本 NamespaceURI:前綴:NodeType:元素 ParentNode:PropertyGroup OwnerDocument:#document IsEmpty:True 屬性:{} HasAttributes:False SchemaInfo:System.Xml.XmlName InnerXml:InnerText:NextSibling
:PreviousSibling:版本值:ChildNodes {} FirstChild : LastChild : HasChildNodes : False IsReadOnly : False OuterXml : BaseURI
: PreviousText :名稱:版本 LocalName:版本 NamespaceURI:前綴:NodeType:元素 ParentNode:PropertyGroup OwnerDocument:#document IsEmpty:True 屬性:{} HasAttributes:False SchemaInfo:System.Xml.XmlName InnerXml:InnerText:NextSibling
:PreviousSibling:版本值:ChildNodes {} FirstChild : LastChild : HasChildNodes : False IsReadOnly : False OuterXml : BaseURI
: PreviousText :名稱:版本 LocalName:版本 NamespaceURI:前綴:NodeType:元素 ParentNode:PropertyGroup OwnerDocument:#document IsEmpty:True 屬性:{} HasAttributes:False SchemaInfo:System.Xml.XmlName InnerXml:InnerText:NextSibling
:PreviousSibling:版本值:ChildNodes {} FirstChild : LastChild : HasChildNodes : False IsReadOnly : False OuterXml : BaseURI
: PreviousText :名稱:版本 LocalName:版本 NamespaceURI:前綴:NodeType:元素 ParentNode:PropertyGroup OwnerDocument:#document IsEmpty:True 屬性:{} HasAttributes:False SchemaInfo:System.Xml.XmlName InnerXml:InnerText:NextSibling
:PreviousSibling:版本值:ChildNodes {} FirstChild : LastChild : HasChildNodes : False IsReadOnly : False OuterXml : BaseURI
: PreviousText :名稱:版本 LocalName:版本 NamespaceURI:前綴:NodeType:元素 ParentNode:PropertyGroup OwnerDocument:#document IsEmpty:True 屬性:{} HasAttributes:False SchemaInfo:System.Xml.XmlName InnerXml:InnerText:NextSibling
:PreviousSibling:版本值:ChildNodes {} FirstChild : LastChild : HasChildNodes : False IsReadOnly : False OuterXml : BaseURI
: PreviousText :更新版本。保存 csproj。版本號已從 6.0.0.6 更新到 6.0.0.6。
WpfApp 版本控制完成
真奇怪。我如何讓它停止這樣做?
uj5u.com熱心網友回復:
感謝您出色的日志記錄,很容易隔離錯誤。在這一行檢查你的語法:
# https://gist.github.com/bcnzer/f8d50699c5bf7614923bff733662cb1a
if ($csprojcontents.Project.PropertyGroup.name -notmatch "Version")
{
Write-Host "Version is null."
#this line below
$csprojcontents.Project.PropertyGroup.AppendChild($csprojcontents.ImportNode(([xml]"<Version/>").DocumentElement,$true))
}
匯入新節點的語法與我通常看到的非常不同。我改變了這樣的語法并且它起作用了。
if ($csprojcontents.Project.PropertyGroup.name -notmatch "Version")
{
Write-Host "Version is null."
$child = $csprojcontents.CreateElement("Version")
$csprojcontents.Project.PropertyGroup.AppendChild($child)
}
至于為什么需要這樣做,這段代碼首先添加了一個版本節點以確保它在那里,然后嘗試將版本設定為正確的值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/315359.html
標籤:小白 电源外壳 powershell-3.0
