2

I'm new to .NET Core. I've published a self-contained version of a test program which runs a simple TCP server, to linux-x64. However, when I publish it, the result is 70MB of the whole SDK. I can remove many of them, and their references within *.deps.json, without the program falling over, so I feel there's a lot of unused references. Is there a tool, or a different method of deployment, which is leaner?

The reason for this is I would like to have an alternate deployment method for a board with only 60MB space - removing Mono and using a native .NET Core program would fit the bill nicely.

Thank you.

Edit: This question is not a duplicate as Resharper's "Optimise References" is unavailable on .NET Core projects. Also, the other VS Extensions only seem to work up to VS2011.

Edit2: I've solved the problem, using .NET Core's ILLinker.

Patrick
  • 419
  • 4
  • 16
  • Possible duplicate of [Removing all unused references from a project in Visual Studio projects](https://stackoverflow.com/questions/3157066/removing-all-unused-references-from-a-project-in-visual-studio-projects) – Sonal Borkar Nov 29 '18 at 17:27
  • 2
    https://github.com/dotnet/announcements/issues/30 .NET IL Linker is the only official tool today. .NET Core 3.0 is supposed to provide a new tool, but not yet fully uncovered. – Lex Li Nov 29 '18 at 20:51

3 Answers3

0

Far as I know, there is no standard solution for it. But there are some solution!

The first is the Visual Studio Extension, which is removed the not used references, it called Reference Assistant And the second one is the ReSharper. The Resgharper is complex extension which has this functionality and many others.

And here is the littel decsription how the resharper works: Remove Unused References With Reshaprer

György Gulyás
  • 1,290
  • 11
  • 37
0

I found the solution to my problem: using ILLinker and the instructions provided here.

It removes not only unused DLL's, but dead code within those DLL's. Initially I didn't get it working, but that article worked.

Patrick
  • 419
  • 4
  • 16
0

Not removing packages but unused code: within .NET Core 3.1 you can use the -p:PublishTrimmed=true argument with your publish command:

dotnet publish --configuration Release --runtime win81-x64 -p:PublishTrimmed=true

In my case this significantly reduced (about a third) the size of the publish folder.

Information can be found here: https://github.com/mono/linker/blob/master/docs/illink-tasks.md

But note their warning you see in the output: Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink

Aage
  • 5,932
  • 2
  • 32
  • 57