我尝试从<ItemGroup>
文件中删除.csproj
个元素,但我的脚本什么也没做。我做错了什么?
脚本:
[xml]$csproj = Get-Content -Path ".\PackageTest.csproj"
$refs = $csproj.Project.ItemGroup | Where-Object {$_.Content.Include -like "PkgFolder\managed*"}
ForEach($ref in $refs)
{
$csproj.Project.RemoveChild($ref)
}
$csproj.Save(".\PackageTest.csproj")
我的csproj文件:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
#
# smthng
#
<ItemGroup>
<Content Include="PkgFolder\managed1.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="PkgFolder\managed2.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="PkgFolder\managed3.zip">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
#
# smthng
#
</Project>
答案 0 :(得分:1)
首先:
$file = gi ".\PackageTest.csproj"
[xml]$csproj = Get-Content $file
第二
$csproj.Save($file.FullName)