I realize this is a rather odd request, but I was wondering if anyone was aware of some minification/obfuscation tools that work on C# source code (not a compiled assembly). I am trying to reduce the character count of an already written application to meet a character limit and I can't seem to find any tools that will help me achieve this task.
Main features I am interested in:
- Strip Whitespace
- Shorten Variable Names
It doesn't have to be a full on obfuscator, just something that will reduce the character count of a block of code quickly and conveniently.
This is not intended to have any practical or real world application, it's for a competition.
-
2Why on earth would you want to do that?Svante Svenson– Svante Svenson09/07/2009 22:22:03Commented Sep 7, 2009 at 22:22
-
My I ask why your code has a character limit?Richard Nienaber– Richard Nienaber09/07/2009 22:22:14Commented Sep 7, 2009 at 22:22
-
I'm trying to meet a chracter limit that's all. Nothing to do with security or anything.Nathan Taylor– Nathan Taylor09/07/2009 22:22:44Commented Sep 7, 2009 at 22:22
-
but why is there a character limit, is it for a comp?Nathan W– Nathan W09/07/2009 22:23:22Commented Sep 7, 2009 at 22:23
-
1I can absolutely do it by hand if need be, but I wanted to see if anyone was aware of such a tool before I went that route. I'm just investigating my options is all :)Nathan Taylor– Nathan Taylor09/07/2009 22:29:16Commented Sep 7, 2009 at 22:29
4 Answers 4
I developed small lib for C# code minification CSharpMinifier based on NRefactory. Now it can remove comments, whitespaces and line breaks. Next I'am planning to add identifier minification.
I am not aware of any such tool, but it would not be too hard to do some variable renaming using the built in refactor tools in Visual Studio.
For the whitespace, a regex find-replace, to replace any multiple spaces (:Wh+ in VS replace) with a single space.
-
1Merging multiple spaces to a single space might break the program if spaces are inside a string literal.Mekanik– Mekanik05/17/2016 22:43:23Commented May 17, 2016 at 22:43
@Ivan's CSharpMinifier didn't work for me. So I am using this one instead. There is a demo web app if you want to try.
-
This one is very good. Although it doesn't minify private member names, it does a good job of minifying the code (~50% for mine)Vinícius Negrão– Vinícius Negrão03/16/2022 16:33:41Commented Mar 16, 2022 at 16:33
This is a good online version to beautify/minify Code Beautify.