How to delete elements in csproj using PowerShell


Zahar

I try to remove the element <ItemGroup>from the .csprojfile but my script does nothing. What am I doing wrong?

script:

[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") 

my csproj file:

<?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>
Zahar

First:

$file = gi ".\PackageTest.csproj"
[xml]$csproj = Get-Content $file

second:

$csproj.Save($file.FullName) 

Related


How to delete RavenDB using Powershell?

Dr. Rob Long How to delete a RavenDB database using Powershell? I know the name of the database (it won't change). I looked into the backup script and I can see that RavenDB can be contacted via a web request: $req = [System.Net.WebRequest]::Create("$ravenUrl/

How to delete elements in a list using delete order?

Ding medicine I have a list like this lst = [1,3,5]and a main list like thislost =['the' , 'cat' , 'thinks' , 'you' , 'are' , 'crazy' ] I want to remove elements in the second list based on the index in the first list. This means I have to remove 'cat', 'you'

How to delete JSONArray elements using Java

yaryan997 : my JsonArray is [{ "Id": null, "Name": "One New task", "StartDate": "2010-02-03T05:30:00", "EndDate": "2010-02-04T05:30:00", "Duration": 1, "DurationUnit": "d", "PercentDone": 0, "ManuallyScheduled": false, "Priority": 1, "parentId": 8, "index": 0,

How to delete elements in an array using RethinkDB

Datsik: I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" ,

How to delete JSONArray elements using Java

yaryan997 : my JsonArray is [{ "Id": null, "Name": "One New task", "StartDate": "2010-02-03T05:30:00", "EndDate": "2010-02-04T05:30:00", "Duration": 1, "DurationUnit": "d", "PercentDone": 0, "ManuallyScheduled": false, "Priority": 1, "parentId": 8, "index": 0,

How to delete elements in an array using RethinkDB

Datsik: I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" ,

How to delete elements in an array using RethinkDB

Datsik: I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" ,

How to delete elements in an array using RethinkDB

Dazik I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "

How to remove attached elements using delete

username I have a simple code with 2 grids. A div contains a button called "Add". When clicked, additional buttons will be added in the second div. When you click any button in the second div it may delete itself. As you can see in the code below, I am using a

How to delete JSONArray elements using Java

yaryan997 : my JsonArray is [{ "Id": null, "Name": "One New task", "StartDate": "2010-02-03T05:30:00", "EndDate": "2010-02-04T05:30:00", "Duration": 1, "DurationUnit": "d", "PercentDone": 0, "ManuallyScheduled": false, "Priority": 1, "parentId": 8, "index": 0,

How to delete elements in an array using RethinkDB

Datsik: I have a table that Lobbysactually contains party rooms, it has an array of Members and an array of Messages, here is an example: { "id": "a77be9ff-e10f-41c1-8a4c-66b5a55d823c" , "members": [ "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" , "Gacnt" ,

How to remove attached elements using delete

username I have a simple code with 2 grids. A div contains a button called "Add". When clicked, additional buttons will be added in the second div. When you click any button in the second div it may delete itself. As you can see in the code below, I am using a

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How does PowerShell delete a directory using FTP?

1212 From this list of web request method fields , I have successfully deleted files from the server via FTP by basically making some changes to the guide on the page by : $url = "ftp://server.net/path/to/place/FILE.txt" $userName = "username" $password = "p@s

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How does PowerShell delete a directory using FTP?

1212 From this list of web request method fields , I have successfully deleted files from the server via FTP by basically making some changes to the guide on the page by : $url = "ftp://server.net/path/to/place/FILE.txt" $userName = "username" $password = "p@s

How to delete all groups with exceptions using Powershell?

Dewey I've seen many examples of using PS to remove all memberships (including main). My working code is as follows: get-aduser person -properties MemberOf | Select -Expand MemberOf | %{Remove-ADGroupMember $_ -member person -confirm:$false} This is great for

How to delete multiple lines in a file using Powershell?

Sam How to delete multiple lines in a file using Powershell? I'm trying to delete some lines (lines 16 to 1463) from a file (notepad) chingNotCHing gc -head + gc -tail should be good enough. For convenience, [System.Collections.ArrayList]$al = (gc yourfile) $a

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How to delete all Azure resources using Powershell

Indigo 8 I need to empty my Azure account from all resources and there are too many to delete individually in the portal. Looking for a PowerShell script to do this. thanks. Edward Rickson Since resources in Azure are divided into Resource Groups (RGs), this i

How does PowerShell delete a directory using FTP?

1212 From this list of web request method fields , I have successfully deleted files from the server via FTP by basically making some changes to the guide on the page by : $url = "ftp://server.net/path/to/place/FILE.txt" $userName = "username" $password = "p@s

How to delete multiple lines in a file using Powershell?

Sam How to delete multiple lines in a file using Powershell? I'm trying to delete some lines (lines 16 to 1463) from a file (notepad) chingNotCHing gc -head + gc -tail should be good enough. For convenience, [System.Collections.ArrayList]$al = (gc yourfile) $a

How to delete node in csproj file in c#?

Deepanka I want to delete node<Reference Include="System.Data" /> Programmatically from a csproj file. My csproj file file structure is like this: <ItemGroup> <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Data.OracleClient" />