4

I'm am really unfamiliar with build output, nuget packages, dll hell, library dependencies, etc.

Before adding this NuGet package to my class library, only one DLL is produced in the /bin folder after I build.

After adding the NuGet package, I get over 100 dlls in the /bin folder.

Is there is a way to only produce one DLL for a c# class library?

When I need to call my class library from a legacy application, I have to copy ALL the dlls in my class library build output to avoid errors - which is somewhat cumbersome.

This is my .csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Intacct.SDK" Version="2.0.5" />
  </ItemGroup>

</Project>
John-Luke Laue
  • 3,736
  • 3
  • 32
  • 60
  • 1
    No, the package would have to be compiled differently by the author. I don't understand why it's cumbersome though. CTRL-a, CTRL-c, ALT-TAB, CTRL-v. It's the same if it's 1 or 1000 files. Or you could create a NuGet package for your class library! Then you just have to add your package to your legacy application and everything would be added automatically. – itsme86 Oct 15 '18 at 19:19
  • Thanks for the answer @itsme86. Just out of curiosity, how would the author have had to compile their library? – John-Luke Laue Oct 15 '18 at 19:26
  • I don't think this is an issue with how the author built their package. They have numerous dependencies for their package. It is going to install all of the dependent packages and their dependencies etc. You will need all of these dll's from various authors in order to use their dll. Just have to copy all and paste ;) – hawkstrider Oct 15 '18 at 19:38
  • I see. Would you guys (@itsme86 and @bhmahler) recommend Pavel Tupitsyn ILMerge answer? https://stackoverflow.com/a/52823470/3878764 – John-Luke Laue Oct 15 '18 at 19:40
  • Welcome to Software engineering. You build your project, it creates one DLL. You bring in a dependency, it brings all of it's dependencies too. You picked up a stick, you pick up the other end too. Just get used to having to copy all the DLL's around. It's not a big deal. – C.J. Oct 16 '18 at 14:30

1 Answers1

4

Yes, you can do that with ILMerge. You'll have to add additional build step:

<ItemGroup>
    <PackageReference Include="ILMerge" Version="2.15.0" />
  </ItemGroup>

  <Target Name="ILMerge">
    <!-- the ILMergePath property points to the location of ILMerge.exe console application -->
    <Exec Command="$(ILMergeConsolePath) /out:MyApp.exe MyApp.exe lib1.dll lib2.dll" />
</Target>

See also Merge DLL into EXE? for some more ideas.

Pavel Tupitsyn
  • 8,393
  • 3
  • 22
  • 44