2

Ever since I've been using the (relatively) new .NET Standard Library project type in Visual Studio, I've been having some problems getting a complete set of DLL files that are required by my project.

The problem is usually limited to 3rd-party libraries which I reference as NuGet packages. I've noticed that these don't get copied to the output folder of my project when I build it. This didn't use to be the case in classic project types.

While I can appreciate the de-cluttering effect that this change has brought for .NET Standard projects, I'm now faced with a problem. I sometimes absolutely need to be able to get the entire list of all files that my project depends on!

I have several different cases, where I might require this list for one reason or another, but the one I believe is most crucial for me, is when I want to gather these files from the csproj itself, right after it's built. In there, I have a custom MSBuild <Target> which should take all the files from the output dir and zip them together for distribution. The problem is, I'm missing all the files that come from NuGet dependencies, because they're not there!

How can I solve this in a general (i.e. not project-specific) way?

UPDATE

There's this deps.json file that contains basically all I'm after and then some. It's just a matter of extracting the relevant information and find the files in the local NuGet cache. But that would involve writing a specialized app and calling it from my target. Before I start writing one myself... Is there something like this already out there somewhere?

ILally
  • 319
  • 1
  • 8
  • 13
aoven
  • 2,248
  • 2
  • 25
  • 36
  • 1
    although I can see the dll of my nuget package libraries when I build my project (console app) in the bin/Debug directory.. you can try to publish your project to a directory and it should include all the required dlls for your app – Benzara Tahar Nov 02 '20 at 16:38
  • @BelahceneBenzaraTahar When I do that, I end up with the nuget package (i.e. the nuget package of my library) in the publish directory. Since I don't want to distribute my library via NuGet, this is definitely not what I'm after. Besides, I want to retrieve the list of dependencies at build time, not at publish. – aoven Nov 02 '20 at 16:41
  • Sounds like you are trying to create an installer. Have you tried one of the VS extensions that create an installer package? – Neil Nov 02 '20 at 16:58
  • @Neil: It's something very similar, yes. But not so involved. I'm trying to create a ZIP file that contains my main DLL and all its required files. This ZIP will then be distributed to a dedicated host, which will analyze it and load its contents as required. Any actual installer in this regard would be an overkill, because the whole process is already established and quite automated. I merely want to avoid having to manually put the ZIP file together after every build. – aoven Nov 02 '20 at 17:11
  • have you consider Costura ? https://github.com/Fody/Costura it bundle your dlls at build phase inside a single exe (not a zip) , don't know if you can exploit that in your case or not – Benzara Tahar Nov 02 '20 at 17:38
  • @BelahceneBenzaraTahar I'm familiar with Costura from my other projects, yes. But I can't use it on this one, because the whole point is to produce a ZIP using all dependent DLLs. This way, the host that will be loading it can decide if the main DLL is compatible with other similar ZIPs and can be loaded in the same process, or if it requires a separate process to avoid version conflicts between dependent assemblies. Nice idea, though! :) – aoven Nov 02 '20 at 17:44

1 Answers1

1

I followed this answer and it sort of works.

The suggested thing was to include the following into my csproj:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

My main concern is that it also outputs some other DLLs from the framework (such as System.Memory.dll and System.Buffers.dll, among others), which I didn't expect. But maybe that's a good thing. They do seem to be dependencies, just not direct ones. I'll see how it plays out.

If it turns out ok, my only wish would be that this directive was more prominently displayed in project settings (as a simple checkbox, maybe?) so I wouldn't have to hunt the web to find it.

aoven
  • 2,248
  • 2
  • 25
  • 36