Converting .exe project to class library

2019-04-18 05:07发布

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.

3条回答
【Aperson】
2楼-- · 2019-04-18 05:43

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.

查看更多
霸刀☆藐视天下
3楼-- · 2019-04-18 05:49

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

查看更多
爷、活的狠高调
4楼-- · 2019-04-18 05:57

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.

查看更多
登录 后发表回答