1

For example, I have two projects sharing some functions, let's say them A and B. So I create another library project C, containing the public code. I put the common code in a class, but in the class, not all the methods are used in both projects. Some of them are only used in A, some only used in B and the rest are used in both of them.

Now, after compiling, I got A.exe, B.exe and C.dll. What I want is:

  1. I don't want the dll, just want A.exe and B.exe

  2. I don't want methods only used in A.exe appears in B.exe, and vice versa.

Merging the dll and exe can solve the problem 1, but how about 2?

iuradz
  • 1,128
  • 1
  • 12
  • 25
  • Each project is going to create their own output. (dll, exe, etc) So getting rid of c's dll seems unlikely. With a and b, if you dont want to expose methods, then make them private or proctected. – crthompson Apr 09 '15 at 21:52
  • I think this is not good idea, but you can put the A methods using internal class in project A, put the B methods in project B, and put common methods in project A then in project B add project A reference. – DanielVorph Apr 09 '15 at 21:58

1 Answers1

1

What you are describing is a static library, not a DLL.

If C were a static library, then when you compile A (with the compiler set to drop unused stuff), A's exe will have all code required by A taken from the static library C and put directly into the exe. The same would go for B.

But that's not how DLLs work.

With a DLL, A is getting the "services" of some code from C, but since the code lives in C, A has no control over what code is in C.

As @RobertMoskal points out, there are answers out there with tools that do what you want. I just wanted to clarify that your intent is counter to the design of Dlls although it can be done with the tools mentioned elsewhere.

DWright
  • 9,258
  • 4
  • 36
  • 53
  • 1
    BTW, all of that said, it's worth noting that .NET does not have static libraries by design. See this for a discussion: http://stackoverflow.com/questions/1835761/why-does-c-sharp-not-have-c-style-static-libraries – DWright Apr 09 '15 at 22:00
  • I have thought a alternative. I can add the source files in C to A and B as link, then I can use the classes and methods in A and B without creating a dll. Now the question is can the compile remove the methods not used in the generated exe? I think my situation is different as I have the source code of the libraries. – iuradz Apr 10 '15 at 00:32
  • Using this solution, i.e., a link, when you have the compiler set to optimize (i.e. Release configuration), it may well discard unused code. You'd have to test it out. – DWright Apr 10 '15 at 00:40