Using sed
For a couple of days now i’ve been pondering about posting something about my love for GNU text-utilities but never got round to it. A couple of minutes ago i read Phil Windley’s Using Grep and Find post so here is a one-liner that shows how you can add a reference to a msbuild target file to all csproj files in a given folder:
find -name *.csproj -exec sed -i -e '#^</Project>$# <Import Project="X:\\BuildTasks\\Corp.targets" />\r\n</Project>' {} \;
Or if you are frustrated with System.Diagnostics.CodeAnalysis.SuppressMessageAttributes and want to remove them from all your cs files:
find -name *.cs -exed sed -r -i -e 's#\[.*?SuppressMessage.*?\]##' {} \";