简体   繁体   中英

Compile a C# solution with multiple projects without producing .dlls

I'm very new to C#, my background is mainly in C w/ some OOP in C++. I'm sure I'm phrasing this incorrectly which is why google isn't helping me but here goes.

I have two programs which use the same class library, when I add the class library to a solution containing one of the programs the class library is compiled as a .dll and then linked to the main solution. Is it possible to compile the library code directly into the solution code?

I can do this by importing the class library code into the the main projects hierarchy but I don't want to do this as I must update any changes to the library in two places..

Should I define my class library as a different entity, is there an option in the solution settings of Visual Studio 2010 to do what I want?

只需通过引用将包含类库的文件添加到项目中,而不是添加为副本。

EDIT:

You can use ILMerge to combine the .dll and .exe. You can't staticly link things in C#. It has to be done dynamically.


If you compile your code as a DLL, and add the project to the references of another project, the compiler will automatically copy the class library to the respective build folder.

C# can automatically find classes, namespaces and functions an application needs when you've specified the reference. There's no need to import any headers, etc, because all of the data is stored in metadata in the DLL, and the .net runtime will look for it automagically. I am also assuming you are working with a C# library.

You are talking about static linking.
There is a tool ILMerge which allows you to do this.
In general in C# this is less of an issue than in C++ because C# Assemblies/dlls offer version information in the assembly header (which you can control in Visual Studio), thus there is no risk of a dll hell.

As the other answerers already said, it is normal .net behaviour that referenced assemblies are just copied into the output folder and NOT compiled into the executable.

There are ways to merge them into the .exe after compiling, but that's not the default, you need additional tools for that.
If you are interested in this, you might want to look at ILMerge or NETZ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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