0

I have a visual studio solution (microsoft visual studio professional 2017) with a main project, that uses classes from a DLL project in the same solution.

The DLL is a "class Library (.NET framework).

Main project is (for my preliminary investigations) a console app. Future versions will be a WPF. I think that the problem appears on all applications that use DLLs that use other DLLs.

The DLL uses other DLLs from a Nuget package. In this case: SQLite. I want to hide to my main project that my DLL uses Sqlite. That makes it possible to change it in future versions to a different database, or maybe use entity framework to access the data.

So my main project only knows that it uses the DLL in the same solution. It does not know that this DLL uses other DLLs.

Problem: These other DLLS are not copied to my main application folder.

This has been asked before: Copying a DLL's dependencies in Visual Studio The answer says that you should use classes from the Sqlite to make sure the DLLs are copied. That is just what I wanted to prevent: users of my DLL should not have to know that this DLL uses SQLite

That question is 11 years old.

I wonder if Visual Studio has now a better solution for this.

Harald Coppoolse
  • 28,834
  • 7
  • 67
  • 116
  • What is your Dll project and your main project type?,net standard lib project for Dll, net framework project for main project? – Mr Qian Jul 23 '20 at 03:09
  • I Edited the question and added the information – Harald Coppoolse Jul 23 '20 at 06:24
  • One more question: did you use this [SQLite](https://www.nuget.org/packages/sqlite/) nuget package and other dlls? – Mr Qian Jul 23 '20 at 06:51
  • I installed Nuget `System.Data.SQLite`, which installed other Nuget packages. The problem also appears if my DLL uses one of my own Dlls. If my main project uses anything of this other Dll, then the other DLL is copied. The problem is: I don't want my main to use anything SQLite. If in future versions I abandon SQLite, I don't want to have to change the users of my DLL – Harald Coppoolse Jul 23 '20 at 06:55
  • the old Net Framework project still needs some custom targets or post build event to copy the dependency dlls into the main project's output folder. You should write a script to realize it. But in new sdk format project, the dlls will automatically be copied into the main project. – Mr Qian Jul 23 '20 at 08:08

1 Answers1

1

A method to solve the problem was given in Install and manage packages in Visual Studio using the NuGet Package Manager. It is not ideal, the main project still needs to know that the other projects use certain Nuget packages, but at least you don't have to edit the .csproj files, nor type command lines

  • MySolution
    • MyMainProject. Refers to MyDll
    • MyDll. Uses Nuget packages

In Visual Studio. Menu - Tools - Nuget Package Manager

The window that opens shows the installed Nuget packages. If you click on them, you can see on the right the projects that use these packages.

For all installed packages that your main program complains that it is missing at run time, check the box near MyMainProject. At the bottom click Install.

Alas, I'd rather have something in project MyDll that tells everyone who uses this DLL that they also need these Nuget packages. But for the time being I'll use this method.

Will check again in 11 years if there is any improvement.

Harald Coppoolse
  • 28,834
  • 7
  • 67
  • 116