在Powershell中连接数组列表时出现错误。
For ($i=0; $i -lt $temp.Length; $i++)
{
$filePath = $filePath.Replace("/", "\")
$fileExt = $filePath.Split(".")[-1]
$Content = Get-Content -LiteralPath $(Build.SourcesDirectory)\$name -Encoding $EncodingType
$OutputFileContent += $Content
$FileObject = New-Object PSobject -Property @{
Path = $filePath
Extension = $fileExt
Contents = $OutputFileContent
}
$changeSet += $FileObject
}
最后一行导致此问题。
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
$changeSet += $FileObject
CategoryInfo : InvalidOperation: (op_Addition:String) [],
ParentContainsErrorRecordException
FullyQualifiedErrorId : MethodNotFound
答案 0 :(得分:0)
不能使用PSObject
运算符将ArrayList
添加到+
。使用Add
的{{1}}方法将项目追加到列表中。
ArrayList
答案 1 :(得分:0)
@gopal,
使用PowerShell的强大功能。您只需在下面进行操作,而无需定义$ changes
$changes = For ($i=0; $i -lt $temp.Length; $i++)
{
$filePath = $filePath.Replace("/", "\")
$fileExt = $filePath.Split(".")[-1]
$Content = Get-Content -LiteralPath $(Build.SourcesDirectory)\$name `
-Encoding $EncodingType
$OutputFileContent += $Content
$FileObject = New-Object PSobject -Property @{
Path = $filePath
Extension = $fileExt
Contents = $OutputFileContent
}
}