-1

In Visual Studio 2015 I have a .net solution that I am working on with multiple classes and forms. Is there a way to make Visual Studio compile a class into its own dll rather than just embedding it into the .exe? I've read stuff about making multiple projects in one solution but that seems like it would create a really ugly file structure and workflow from a development side.

Thanks

edit

Each class is currently in its own file. Having multiple projects just for a .dll file seems like a really roundabout way of doing something.

I have found Can C# compiler compile a VB.Net code? solution on SO which works great for c# but i didnt think id have to do anything at the compiler level. I also have vb.net classes in that id like for this to work on if possible.

Bigbob556677
  • 1,805
  • 1
  • 13
  • 38
  • Why do you want to do this? Sounds like an X-Y problem. – xxbbcc Nov 09 '17 at 15:07
  • Why do you want/need this? Seems like an XY problem. – Sami Kuhmonen Nov 09 '17 at 15:07
  • @xxbbcc Because when im working on one project and i write a class in that project that could be used in another project, id like to be able to reference the .dll to the second project without having two separate versions of the same class. – Bigbob556677 Nov 09 '17 at 15:11
  • @SamiKuhmonen See above. – Bigbob556677 Nov 09 '17 at 15:12
  • 1
    @Philip556677 I see; your question reads very differently. – xxbbcc Nov 09 '17 at 15:15
  • 1
    Possible duplicate of [Creating a .dll file in C#.Net](https://stackoverflow.com/questions/15567893/creating-a-dll-file-in-c-net) – xxbbcc Nov 09 '17 at 15:16
  • @xxbbcc I want a class to compile to its own dll. My put didn't provide context. It just housed the question itself. And almost. the only issue is. When it compiles, i need the exe and the dll. or at least would like to have them. Thanks though – Bigbob556677 Nov 09 '17 at 15:17
  • @Philip556677 can you please [edit] your comments into the post and additionally clarify what you mean "would create a really ugly file structure and workflow from a development side"? Whatever approach you going to use will require to specify dependencies between your classes somehow and projects already have it built in... – Alexei Levenkov Nov 09 '17 at 15:42
  • Also clarify how you want to deal with `internal`/`private` classes and if multiple classes per file must be split into separate DLLs. – Alexei Levenkov Nov 09 '17 at 15:53

1 Answers1

2

Just put your classes you want to have in their own .dlls into a new .csproj (Assembly) and set the output type to "ClassLibrary" that way the projects will all get their own .dll-File when compiling.

This is the way how you share classes/interfaces/enums/etc. between different projects/solutions.


Edit:

If you want to get one class compiled into a class library and an executable file, you'll have to change the structure of your code. You may need to extract some methods/properties into one or more new class(es) and then do what i wrote above.

Tobias Theel
  • 3,088
  • 2
  • 25
  • 45
  • 1
    While this is clearly not an answer to the question (as OP already rejected making multiple project idea) I don't see any other solution that would provide reasonable tooling support.... Indeed OP can use CSC to compile each file into DLL, but handling dependencies would be nightmare for most people (unless one is makefile guru) – Alexei Levenkov Nov 09 '17 at 15:56
  • @AlexeiLevenkov I have found https://stackoverflow.com/questions/20826999/can-c-sharp-compiler-compile-a-vb-net-code solution on SO which works great for c# but i didnt think id have to do anything at the compiler level. I also have vb.net classes in that id like for this to work on if possible. – Bigbob556677 Nov 09 '17 at 16:01