I am working with the following command:
get-content C:\somepath\Setup.csproj |
select-string -pattern '<None Include="packages.config" />' -notmatch |
Out-File -filepath C:\somepath\Setup.csproj -force
The idea is to remove any lines in Setup.csproj that have the text <None Include="packages.config" />
.
However, when I run the above command, my Setup.csproj file is emptied (it goes from have a bunch of text to having no test).
But if I change the command to output to a new file, Setup2.csproj, then the new file is created and has the content I want:
get-content C:\somepath\Setup.csproj |
select-string -pattern '<None Include="packages.config" />' -notmatch |
Out-File -filepath C:\somepath\Setup2.csproj -force
This works fine, and I suppose I could then delete the original and rename Setup2.csproj to be Setup.csproj, but if it can be done in one step, I would prefer it.
Is there a way to use the get-content and select-string methods above and then call Out-File on the SAME file?
(Note, I got the above example from this question.)