C# 静态库

发布于 2024-11-30 23:31:57 字数 317 浏览 1 评论 0原文

当我用c语言编程时,动态库和静态库之间的区别在于你在makefile中编译程序的方式。正如我们所知,Dll 并不是硬编码到应用程序中,而是位于单独的文件中。这使得它们非常适合更新程序和向程序添加功能。编译时的静态库被硬编码到应用程序中。这对于将来不需要改变的行为来说是完美的:比如安全或基本通信。

我知道如何在 C# 中创建和调用 .dll 文件,但我需要创建和使用静态库。 无论如何,是否可以在不将类库复制/粘贴到每个项目中的情况下执行此操作?我有很多项目使用这些静态库,并且我希望避免在引入更改时必须更改所有类库。

我用谷歌搜索了这个,但没有找到解决方案。

多谢...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

被翻牌 2024-12-07 23:31:57

您可以找到的最接近的是 ILMerge - 但您真的需要这?除非您有一个可以作为单个可执行文件部署的应用程序,否则无论您拥有一个还是十个 DLL 都没有多大关系。我建议在大多数情况下,您应该将它们保留为普通的类库。

请注意,ILMerge 与“静态链接”并不完全相同 - 它仍然执行将所有代码捆绑到单个文件中的工作,但 .NET 中的链接过程与本机代码的链接过程从根本上有些不同。

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.

胡大本事 2024-12-07 23:31:57

是的,您可以使用 ILMerge,它将多个程序集中的 IL 代码合并到一个程序集中。像 NuGenUnify 这样的 GUI 前端使 ILMerge 的使用更加简单。

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.

﹎☆浅夏丿初晴 2024-12-07 23:31:57

根据您的要求,除了 ILMerge 之外,您还可以使用“.NET 模块”。此博客提供了有关之间的区别网络模块和程序集

但请注意,Visual Studio 不直接支持网络模块。您基本上必须使用 C# 编译器的 /target:module选项(可能还有程序集链接器al.exe)手动使用它们。

顺便说一句,据我所知,它们是创建来自不同 .NET 语言(VB、C# 等)的不同源文件的程序集的唯一选择。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文