-1

I am building a C# project in Jetbrains Rider. When the project is finished, I want to include it in another project by building a dll and adding the dll to the project. To generate a dll, I need to set the Output Type to Class Library.

However, this means that I cannot run the project directly. Class Libraries are not runnable; if you want that, you are supposed to make a Console Application. Every time I want to test, I have to replace the dll in the other project, then run the other project. This might not seem that bad, but the problem is that my dll is only used in some places in that project.

Also, not being able to run as a console application makes debugging a lot harder since I can't write to / read from the console.

There are probably some hacky ways to get around this - while struggling around trying to come up with a solution to my problem, I have thought of a few hacky and painful methods to get what I want. However, I am looking for a clean solution. One project, same code. Built to class library when I click build, run as console application when I click run.

The best compromise I have come up with so far is to switch between Class Library and Console Application output types whenever I want to build or run. However, this is still a hacky and painful way. It's also prone to error, and if someone else wants to work on my project, there's no way to let them know other than a big ugly warning at the beginning of the README.

There must be a better way to do this. I mean, how are you supposed to test your class library? I am willing to compromise, but there doesn't seem to be anything holding back a clean and easy solution. Right?

  • 4
    The best solution is to use unit tests. Write code, validate with test, repeat. If something breaks after change - you will know. I recommend using XUnit, since it's most popular solution and have more than enough documentation and blog posts – JL0PD Jul 21 '23 at 01:45
  • https://www.jetbrains.com/help/rider/Getting_Started_with_Unit_Testing.html – Jon P Jul 21 '23 at 01:46
  • The problem with this is that I am building a GUI. I need to actually run it so I can see how it looks and make adjustments. – Zeek Joseph Jul 21 '23 at 02:31
  • I forgot to mention you in my previous comment, but I can't edit it (I guess it's restricted by my low karma), so I'll mention you here - @JL0PD Update: What the heck? I can edit this comment, but not said previous one. Weird. – Zeek Joseph Jul 21 '23 at 02:51
  • @ZeekJoseph You can edit comment within 5 minutes after posting – JL0PD Jul 21 '23 at 03:45
  • Ohhh, that makes sense! I never noticed that xD – Zeek Joseph Jul 21 '23 at 05:52

1 Answers1

0

This is how I usually test my DLL:

  1. Create a project Class Library, build your code.
  2. In the solution add a new project console for testing.
  3. In the project Console add reference DLL form project Library.
  4. Rebuild solution after editing code from Class Library, test in Console project.
Lee Dungx
  • 91
  • 4
  • This solution works, but it is still a hacky workaround. First off, I would have to add a build event to compile the class library in the console application run configuration, which is hacky and still means I need to leave a big ugly warning in the README for people who want to work on my project. Also, it requires two projects, which I am strongly against (maybe I mentally overexaggerate how big of a deal it is, but I hate the idea of it and I'm sure it must violate some principles of software development). But thanks for the suggestion - I will consider it if I don't find anything better. – Zeek Joseph Jul 21 '23 at 02:34
  • By the way, welcome to Stack Overflow! – Zeek Joseph Jul 21 '23 at 02:53
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 24 '23 at 15:30