views:

3556

answers:

8

How can I convert my C# code to DLL file in a way that the user of DLL can’t view my source code?

When I make DLL in the way I always do by making a class library project, importing my classes and compiling it, the source code can still be viewed.

+1  A: 

Consider using an obfuscator.

Anton Gogolev
+4  A: 

obfuscation is what you want to search for.

There is a free one (that is limited) in visual studio called Dotfuscator.

Uses fancy methods to rename your code and alter flowpaths to obscure it.

Spence
A: 

are you talking about ASP.NET ? Websites ? hide the aspx and cs source codes?

if yes, please see my question :

http://stackoverflow.com/questions/461842/pre-compile-website-in-setup-deployment

:)

balexandre
No, the question is about a few classes written in C#.
Ali
ok, then you need an obfuscator :)
balexandre
A: 

If you mean, the end-user can view your source code by decompiling it, you can protect yourself using an obfuscator.

There is standard obfuscator build in into Visual Studio. In the menu choose Tools / Dotfuscator community edition.

GvS
+1  A: 

If you are developing desktop applications converting your code to Dll will not hide the it( there are many tools to decompile the dll or exe files).

but if you are using Asp.Net, then you can compile your site to Dll, and the code will not be visible in the aspx pages, it will be compiled to Dll, you can do that by right click on your project on solution explorer, then choose Publish website

But in all cases .Net Exe files and DLL will be easy to decompile and extract the source code again, unless you use tool to obfuscator your code.

Mohammed Nasman
And even with an obfuscator your .NET code remains easier to reverse-engineer than if you compiled C++ code straight down to native machine code. And even that can be broken. Security through obscurity will only take you so far...
Vojislav Stojkovic
Right, because that I use Delphi win32 as primary IDE for developing desktop applications ;-)
Mohammed Nasman
+6  A: 

I believe you are looking for an obfuscator. This is a tool that will take a compiled DLL and rewrite the code with the intent of it not being meaningfully decompiled by another user. Visual Studio comes with a free Dotfuscator

Note, this will not actually prevent people from looking at your code. They will instead be looking at a very weird translation of your code. There is no way to prevent people from looking at decompiled versions of your code in C# or any other .Net language for that matter.

This is not something that is unique to C#. It is fact a flaw of every language in existence. It's perfectly possible to decompile C code. The difference though is it's much easier to maintain a lot of the original code structure when decompiling managed languages (.Net and Java for instance) because the metadata maintains the original structure.

JaredPar
A: 

I think my reply to a similar question about JavaScript obfuscation applies here as well: in short, why bother? Your question has already been answered here ("use an obfuscator"), but I thought it wouldn't hurt to find out what your motivations are. Generally, code that you give to people is "in the hands of the enemy" -- if somebody wants to use it/figure out how it works badly enough, they will.

Coderer
A: 

check out smartAssembly at www.smartassembly.com