Ali
Ali

Reputation: 5416

How to convert C# to DLL to hide the source code?

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.

Upvotes: 1

Views: 20099

Answers (6)

Coderer
Coderer

Reputation: 27244

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.

Upvotes: 0

JaredPar
JaredPar

Reputation: 754545

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.

Upvotes: 10

Mohammed Nasman
Mohammed Nasman

Reputation: 11050

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.

Upvotes: 1

GvS
GvS

Reputation: 52518

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.

Upvotes: 0

Spence
Spence

Reputation: 29322

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.

Upvotes: 4

Anton Gogolev
Anton Gogolev

Reputation: 115691

Consider using an obfuscator.

Upvotes: 1

Related Questions