11

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.

asked Sep 7, 2009 at 22:18
8
  • 2
    Why on earth would you want to do that? Commented Sep 7, 2009 at 22:22
  • My I ask why your code has a character limit? Commented Sep 7, 2009 at 22:22
  • I'm trying to meet a chracter limit that's all. Nothing to do with security or anything. Commented Sep 7, 2009 at 22:22
  • but why is there a character limit, is it for a comp? Commented Sep 7, 2009 at 22:23
  • 1
    I 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 :) Commented Sep 7, 2009 at 22:29

4 Answers 4

6

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.

answered Oct 29, 2013 at 7:43
5

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.

answered Sep 7, 2009 at 22:33
1
  • 1
    Merging multiple spaces to a single space might break the program if spaces are inside a string literal. Commented May 17, 2016 at 22:43
4

@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.

answered Feb 9, 2020 at 13:39
1
  • 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) Commented Mar 16, 2022 at 16:33
0

This is a good online version to beautify/minify Code Beautify.

answered Feb 11, 2015 at 8:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.