How can i pack all my classes into a package or DLL for future projects?

I’m new to Monogame, and I’ve created several classes to deal with physics and collisions. I want to re-use those classes, so is there a way for me to pack them all into a package or DLL for future projects?

Hi Coosis,
In Visual Studio, you can add a new Class Library project to your solution and add your classes to that project.

In the solution explorer, right click on the solution name and select Add > New Project, then look for Class Library. Once you’ve created a new project in your solution, you can add all the classes that you want to reuse.

You’ll have to add a reference to this project though, so in the solution explorer again, under your MonoGame project, right-click on Dependencies and Add Project Reference, then select your class library project.

When you build your solution, the class library project will output a .dll file which you can then reference from other projects or solutions.

Note there is a limitation here as your library project cannot have a reference to your game project since that would create a circular dependency, but you can still have references to MonoGame types.

1 Like

Hi NiroSolis,
Thank you so much for the detailed reply. So you are suggesting i create a project for building my own dll. I guess i will have to do it now. I thought there would be an easier way. I would love to follow the steps in Visual Studio, but unfortunately i only use vscode.
For those who use vscode like myself, here’s how you can do the same:

  1. Open up the terminal, navigate to the path you wish to put the project’s folder in using cd command
    (cd C:\Users\username\xxx\yyy)
    (or if you are already on C:\Users<username>\xxx you can just do cd yyy)

  2. type dotnet new classlib -o [desired dll name]
    (o is short for output, and to see all the templates available, type dotnet new -l)

  3. type cd [desired dll name] and you are good to go.

  4. to output, open the terminal, type dotnet build -o and you will find the dll there.