I would like to remove all blank lines (lines that just have some number of spaces and a newline character) from a list of files using MSBuild.
What is the best way to accomplish this?
I recognize that I could write a MSBuild plug in C# or VB.NET that will do this using simple Regex replacement, but would prefer a solution that doesn't need me to do this.
If there's a open source MSBuild plugin that does this - I'd welcome that solution as well.
@Ludwo is right, you have to take into account white-space characters. Moreover to replace any text with empty string you need to use ReplacementTextEmpty
property instead of passing empty string to ReplacementText
property. So, the following target should solve the problem:
<Target Name="Minify">
<ItemGroup>
<File Include="**\*.cs" />
</ItemGroup>
<FileUpdate
Files="@(File)"
Regex="(\n\s*\n)+"
Multiline="False"
ReplacementTextEmpty="True"/>
</Target>
You just need to call the target via MSBuild:
msbuild MyProject.csproj /t:Minify
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With