I have a .NET C# application which should be run only on one computer with known configuration (HP DL120 G7, Xeon E3-1220, Windows Server 2008 R2 Foundation if this is important). I don't need to run this application on other computers.
I want to:
- make it as fast as possible (i.e. probably compile with "use Xeon E3-1220" key or something?)
- secure it a little bit (it should not be trivial to restore C# source code 开发者_运维问答from binaries).
Should I compile to native Windows code somehow? Probably I should use some special compiler options?
You can compile it in "Release" mode to enable optimizations. Also, you can run ngen.exe to generate native DLLs which will not incur the overhead of JIT.
However, keep in mind that all these measures and tools are not a silver bullet for a poorly written code (not saying that yours is). You should profile your app and see if you can improvise the execution time of any code path as well as find out the slower paths (and seek to improve them).
To secure it, use a good obfuscator such as (Salamander, SmartAssembly etc.). It won't be entirely indiscernible but it'll make it lot more harder.
To absolutely secure it, code it in C++! You can compile it with /clr
option which will make them immune to reflection and disassembly.
It's easy to restore code from .Net assemblies. You can go some way by obfuscating the contents (google for this).
As for compilation, the CLR will compile it efficiently when the process is started - you shouldn't have to worry about this. If the startup time is high, you can use ngen (AOT compiler) to compile your assembly:
http://en.wikipedia.org/wiki/Native_Image_Generator
If you want to make sure it's fast, make sure you compile in release mode though, with optimisations (it will be in your project properties).
You can use ngen to create and cache optimized native images of your assemblies.
精彩评论