Converting .exe project to class library

独自空忆成欢 提交于 2019-12-06 17:01:03

问题


I have a semi-large C# .exe project in visual studio 2010 Ultimate, and I would like to convert it to a DLL class library. Is there an easy way to do this that doesn't involve creating a new class library project? Thanks beforehand.


回答1:


Project > Properties > Application tab, change Output type to "Class Library".

For the record, this isn't actually necessary. An EXE project works fine as an assembly reference. Assuming classes were declared public, something you might have to fix anyway to make them work in a library.




回答2:


In .NET, an .exe and a .dll are both legal as references. This is because in .NET, there exists two type of assemblies:

  1. process assemblies - known in public as executables, or exe
  2. library assemblies - known in public as dll

An assembly in .NET holds many modules, that in turn holds one or more classes (the guideline is one class per module). These modules is turned into IL code at compile time and JIT'd at runtime. The important part for both types of assemblies is that each assembly holds meta data like

  1. modules
  2. methods
  3. types

there exists in an assembly. And because of that the runtime, and compiler, can easily determine how to fx call a certain method in a process assembly.

I think, without being an expert on the subject, that the major difference between process assemblies and library assemblies is that process assemblies holds some extra code, telling the runtime how to load, and what to load.




回答3:


Go into My Project in your solution, select the Application tab, and change the Application type to Class Library.



来源:https://stackoverflow.com/questions/8524790/converting-exe-project-to-class-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!