简体   繁体   English

引用另一个项目?

[英]Reference to another project?

When I create a reference to another project (a library) thats part of the same solution in Visual Studio, is that project then compiled into my assembly, or does it link to the assembly created by the other project? 当我创建对另一个项目(库)的引用,而该引用是Visual Studio中相同解决方案的一部分时,该项目然后被编译到我的程序集中,还是链接到另一个项目创建的程序集? I'm wondering if I need to distribute both assemblies, or if I can distribute just one. 我想知道我是否需要分发两个程序集,或者我是否只能分发一个程序集。

If the latter (have to distribute both), how can I force it to compile into one assembly? 如果是后者(必须同时分发),我如何强制将其编译为一个程序集?

is that project then compiled into my assembly, or does it link to the assembly created by the other project? 然后将该项目编译到我的程序集中,还是将其链接到另一个项目创建的程序集?

The other project is in its own assembly; 另一个项目在自己的程序集中; it's not compiled into yours. 它没有被编译到您的文件中。

I'm wondering if I need to distribute both assemblies, or if I can distribute just one. 我想知道我是否需要分发两个程序集,或者我是否只能分发一个程序集。

You have to distribute both. 您必须同时分发。

how can I force it to compile into one assembly? 如何强制将其编译为一个程序集?

There's no built-in way to do this with Visual Studio, other than moving the source code from the other project into the main one. 除了将源代码从另一个项目移动到主项目之外,Visual Studio没有内置的方法来执行此操作。 You could take a look at ILMerge . 您可以看一下ILMerge

By default the library project will produce a separate assembly/dll. 默认情况下,库项目将生成一个单独的程序集/ dll。 According to this post 根据这篇文章

Linking statically in C# 在C#中静态链接

you can use ILMerge though to merge these separate dlls into a combined one though. 您可以使用ILMerge将这些单独的dll合并为一个合并的dll。

You can use pre-build action on project's property page to copy source files from other project(s) into main. 您可以在项目的属性页上使用预构建操作,以将源文件从其他项目复制到主文件中。 This way you'll only modify source in one place and always have a separate dll as an option. 这样,您将只在一个地方修改源,并且始终有一个单独的dll作为选项。 When you'll decide to use dll remove copied source files and pre-build action and add reference to library project(s) 当您决定使用dll时,请删除复制的源文件并进行预构建操作,并添加对库项目的引用

如果您引用另一个项目,则编译器将为执行整体解决方案所需的每个项目生成一个dll文件。

Solution file is used to just work easily, and manage projects it doesn't make any change to manner of default projects, may be you want install shield? 解决方案文件用于轻松工作和管理项目,它不会对默认项目的方式进行任何更改,也许您需要安装shield? have different Dlls is not bad thing, you can grow your Main project better. 具有不同的Dll不是一件坏事,您可以更好地发展Main项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM