Visual Studio 2022, MonoGame & DLLs

This is as much a Visual Studio 2022 question as a MonoGame & DLL question. I’ve been writing the AI for my game as a DLL in a WPF App. It’s called TacticalAILib and, in part, it looks liked this:

I want to add this DLL to my MonoGame project. Just adding it didn’t work. ALSO: it would be really great if what I actually imported into the MonoGame project would allow me to modify the source (and that there would be only one set of source as opposed to Visual Studio copying all the files over to the MonoGame folder; which is what it does if I just import all the files).

Thanks in advance. More stupid questions to follow.

You can add a project to a solution without modifying the location of the project, giving you easy access to the project within Visual Studio’s solution explorer. Just right click the solution title in the solution explorer and click “Add existing project”. It will add the project to the solution without copying it or moving it over.

If you build your library project, it’ll create a DLL file that you can then add to the MonoGame project’s dependencies. I have done this with my own personal game library. Anytime you modify the library code you’ll then need to rebuild it so that the updates get pushed to the DLL file that the MonoGame project references.

You can also configure the library project to save both the debug and release DLL in the same location, making it easy for your project to use either the debug or release build of the DLL (depending on what was most recently built) without having to change the dependency.

1 Like

Please tell me how to do this. This is exactly what I need. Thanks. Also, how do I add the DLL to the MonoGame project’s dependencies? Again, many thanks. (Is it Add Project Reference… or Add Shared Project Reference… ?

Um, I actually don’t remember how to make it build to the same place. I’m pretty sure I’ve done it before, but for some reason I can’t get it to work now. Sorry. So, I guess, just build in debug mode until you’re ready to release, unless you need to profile performance with the optimizations of release enabled. Then you’ll have to manually change the project reference/dependency back and forth.

Yeah, just use “Add Project Reference” and navigate to the folder where the library’s DLL file was built and placed.

Thanks! Man, nothing gives me a throbbing headache faster than either dealing with hardware or setting stuff up in VS.

Yeah, I don’t know why it’s suddenly hard to configure it to build to the same directory for both debug and release. I believe in the past I was able to change the currently active configuration to “All Configurations” and do it that way, but I seem to no longer have that option.

I love writing code (C#, C++, just let me write). Hate dealing with environments, IDEs and setting up projects.