开发者

C# Static Libraries

When I use to program in c, the difference between a dynamic library and a static one was the way you compiled the program in the makefile. Dlls, as we know, are not hard coded into the app, but are in separate files. Which makes them perfect for update and adding functionality to a program. Static libraries on compile time are hard coded into the app. Which is perfect for a behavior that will not need to be changed in the future: like security or basic communication.

I know how to create and call .dll files in c#, but I need to create and use static libraries. Is there anyway to do this without copy/paste a class library into each project ? I have a lot o开发者_开发技巧f projects that use these static libraries, and I want to avoid having to change all class libraries when I introduce a change.

I googled this, but came out with no solution.

Thanks alot...


The closest you can come is ILMerge - but do you really need this? Unless you have an application which you can deploy as a single executable, it doesn't much matter whether you have one DLL or ten. I would suggest that for most cases, you should just keep them as normal class libraries.

Note that ILMerge isn't quite the same as "static linking" - it still does the job of bundling all the code into a single file, but the linking process in .NET is fundamentally somewhat different to the one for native code.


Yes you can use a tool such as ILMerge, which will merge IL code from multiple assemblies into a single assembly. A GUI front-end like NuGenUnify makes using ILMerge much more striaghtforward.


Depending on your requirements, and appart from ILMerge, you could also use ".NET Modules". This blog provides some information on the difference between netmodules and assemblies.

Note, however, that netmodules are not directly supported by Visual Studio. You basically have to use the C# compiler's /target:module option (and possibly the assembly linker al.exe) manually to use them.

AFAIK, btw, they are the only option to create assemblies where different source files originate from different .NET languages (VB, C#, etc.).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜