How to mass-edit *proj files in VS
-
In powershell, we first rename all csproj files to csprojxxx; so VS does not try to open them as projects instead treat them as text files:
ls -r *.csproj | rename-item -force -newname { [io.path]::ChangeExtension($_.name, "csprojxxx") }
-
In File Explorer, navigate to project directory and search for *.csprojxxx, then drag all the items onto a new VS instace.
-
In VS, use regex to capture a whole line by a keyword, for example
(^.*Microsoft\.Common\.props.*\n)
will select the entire line:(note two white spaces before the text)
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
then the replace text:
(note two white spaces before the text)
<Import Project="$(SolutionDir)\My.Common.props" />\n$1
this will form:
(note two white spaces before each line)
<Import Project="$(SolutionDir)\My.Common.props" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
-
Finally rename all
csprojxxx
back tocsproj
ls -r *.csprojxxx | rename-item -force -newname { [io.path]::ChangeExtension($_.name, "csproj") }