Skip to content

Instantly share code, notes, and snippets.

@DontPanic345
Created October 11, 2016 22:51
Show Gist options
  • Save DontPanic345/b049a36241d21423fadefeaae80f8269 to your computer and use it in GitHub Desktop.
Save DontPanic345/b049a36241d21423fadefeaae80f8269 to your computer and use it in GitHub Desktop.
Update C# and VB project files to only copy files to the output if the file has changed
My C# and VB.net project files contain many lines
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
and I want them to say
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
so the gist of it is
find -regex '.*\.vbproj\|.*\.csproj' -exec sed --in-place --binary 's:<CopyToOutputDirectory>Always</CopyToOutputDirectory>:<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>:' {} \;
Explaination:
find Finds files
-regex search by expression, this isn't the same regex as grep tho so watch out!
-exec will execute the given command with {} substituted with each of the file names
\; ends the -exec command with substituting one file name at a time
sed Steam EDitor
--in-place edit the files inplace (makes a backup if suffix supplied)
--binary Using Mingw on windows so this flag is required to corretly handle the end of line characters
s:old:new: substitue command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment