How do I compile C# code as a library instead of an executable?
Solution 1
You do not need to build it as a dll. VS 2010 (and IIRC 2008) allow referencing exe assemblies. All you need is for they relevant types to be declared public
- top-level classes defualt to internal
if you don't add a specifier.
Solution 2
You can switch output type to Class library in project properties as well - then you will have an output as dll instead exe file
RexE
Updated on June 09, 2022Comments
-
RexE almost 2 years
I have a C# console application in Visual Studio 2010. It has a Main() method as well as a bunch of utility classes. I'd like those utility classes to be available to other solutions. From reading online it seems that I need to compile it as a Class Library (DLL). So here's what I did:
- Went in Visual Studio to "Project > [ProjectName] Properties > Application" and changed "Output type" from "Console Application" to "Class Library"
- Rebuilt; ProjectName.dll was created in bin/Debug.
- Created a new Console Application
- Solution Explorer > Add Reference > browse to ProjectName.DLL, select it.
However, neither IntelliSense nor the Object Browser could find the classes inside that DLL.
I tried recompiling several different Console Applications as Class Libraries and got the same result. I also noticed that it works if I initially create the solution as a Class Library, but not if I convert it to one later.
Any tips?
-
Ethan Bierlein over 8 yearsCouldn't someone also just create a project with the type of "Class Library" instead?