我目前是这样写,但是没有效果,
我的意图是想把所有的资源文件设置为Content.
param($installPath, $toolsPath, $package, $project) $project.ProjectItems | ForEach { $_.ProjectItems } | where-object {$_.Name -match "\.\w{2}\-\w{2}\.resx"} | Foreach {$_.Properties.Item("BuildAction").Value = [int]2 } $project.Save()
原来是保存的问题,理论上设置了BuildAction之后,
需要Unload 在Reload 项目设置才能生效,更简便的方法就是分别调用两次Save方法
param($installPath, $toolsPath, $package, $project) function Search-ItemsRecursive($projectItems, $list){ ForEach ($item in $projectItems) { $itemName = $item.Name #Write-Host "Getting all project items for $itemName" $list.Add($item); if($item.ProjectItems -ne $null){ Search-ItemsRecursive -projectItems $item.ProjectItems -list $list } } } $project.Save() $projectName = $project.Name Write-Host "Getting all project items for $projectName" $items = New-Object System.Collections.ArrayList($null); Search-ItemsRecursive -projectItems $project.ProjectItems -list $items #$items = Get-AllProjectItems ForEach ($item in $items) { if($item.Name -ne $null ` -and $item.Name.EndsWith(".resx") -eq $true ){ $itemName = $item.Name; Write-Host "Setting [BuildAction] of item $itemName"; ForEach ($property in $item.Properties) { if($property.Name -eq "BuildAction"){ $property.Value = 2 } } } } $project.Save()