0

Im coding in c#. already written a portable console application that needs a dll to work with and it works perfect without any error.

I want to get rid of carrying that dll everywhere and copy its source or some of its classes. Im already using NetShrink software for making my exe and dll a package but its a kind of trick and not a original way.

MyQuestion: Is there any original way in visual studio or any plugins to bring a dll source into another project ? i heard from an old programmer that there is a built-in tool that bring whole .dll source to project.

What i tried: except Netshrink i tried assembly-explorer in Resharper plugin and get output as .sln project from .dll but thing get hard with this.

the dll is Ionic.Zip.dll in DotNetZip used for compressing files.

  • There is no "original" way for merging assemblies. Microsoft ships ILMerge for this purpose but there are way better tools like LibZ to merge assemblies. Normally you wouldn't merge assemblies because you should create installers. But when developing portable applications it's fine. – Christian Klemm Sep 10 '17 at 14:07
  • thanks let me try these. – DewinaTwice Sep 10 '17 at 14:09
  • What is wrong about the tool you are currently using? – Christian Klemm Sep 10 '17 at 14:09
  • "I want to get rid of carrying that dll everywhere and copy its source or some of its classes" -> Then why not just take the sourcecode: https://dotnetzip.codeplex.com/ – Peter Bons Sep 10 '17 at 14:09
  • @chris579 packaging with netshrink make it act differently in some cases like ErrorHandling and it can be depackaged and the dlls inside will be seen. which is not what i want – DewinaTwice Sep 10 '17 at 14:15
  • @PeterBons i have already downloaded this. it does not included source code, its just bunch of dll's , if im not wrong – DewinaTwice Sep 10 '17 at 14:17
  • Hmm I see a .sln file and most of the code is in the ZLib assembly: https://dotnetzip.codeplex.com/SourceControl/latest#Zlib/Deflate.cs – Peter Bons Sep 10 '17 at 14:27
  • You are mixing up obfuscation with merging. When developing in .NET you have to deal with decompiling. – Christian Klemm Sep 10 '17 at 15:46

2 Answers2

0

Actually there is no way around it. You have several options to deal with your portable project.

  1. Add the library project to your solution and reference it.
  2. Add the library (.dll) to your solution and reference it.
  3. Add the library (.dll) to your solution and Load it from Resources
  4. Merge the (.dll) to your .exe with 3rd party tools (e.g., NetShrink)
  5. Upload your library (.dll) to a NuGet Server and just install it (You could setup your own NuGet Server or use the Microsoft one)

I personally use approach number 3. Copy the .dll to my solution somewhere, reference it, load it on demand and do not copy it to the output folder. If possible, stick to approach number 5. since its the most convenient one.

Bin4ry
  • 652
  • 9
  • 34
0

You are actually mixing up obfuscation and merging. Your goal is to hide referenced assemblies that are packed into your assembly.

For a reference look at this question: How can I protect my .NET assemblies from decompilation?

Regarding your original question you are already good to go. As I suggested you could use LibZ or ILMerge (or another tool, there are dozens of them).

You definitely should be more specific in your question as you want to protect your assemblies against piracy and not merge them together.

Christian Klemm
  • 1,455
  • 5
  • 28
  • 49
  • Thanks. I used both ILMerge and LibZ and both worked. but it seems it will do something like Netshrink just merge .exe and .dll into a .exe , what i want is to bring the dll source to my project. – DewinaTwice Sep 11 '17 at 10:26
  • And my purpose is not protecting my code or obfuscation ... Just want to bring all dependencies and dll's into a single file. Found [this](https://marketplace.visualstudio.com/items?itemName=Vitevic.VitevicAssemblyEmbedder) but don't know how to use it. – DewinaTwice Sep 11 '17 at 10:30
  • The tool you linked is exactly doing what you don't want. If you want to bring the source code to your project you just have to include the source of the reference. But tbh this is not how you should handle external dependencies... Plus I don't know why somebody should even want to include the source directly. – Christian Klemm Sep 11 '17 at 13:11