Is it possible to make Visual Studio to copy all dependencies of referenced projects into the output path?
In the Solution, Project A (Library, .NET Standard) defines some functions and is dependent on Library L1 (via NuGet) and Library L2 (local .dll
, referenced and copied to project)
Project B (Console Application) references Project A.
When building B, The output folder contains all direct dependencies of B and A.dll
. L1 and L2 are not available in the output. Therefore, the program does not work correctly.
How can I force VS to copy also L1 and L2 to the output of B?
The only way I found so far is packing A as NuGet, but this seems to be unnecessary overhead and uncomfortable. I think I am just forgetting something everyone else seems to know...
My solutions consists of two projects.
When debugging the ConsoleUser
application, it compiles and starts. During runtime, when it calls a method in the MongoWrapper
which uses the MongoDB.Driver, the application crashes, as the MongoDB.Driver dependency was not copied into the output folder of the ConsoleUser
.
How to fix this?
The problem was introduced by the usage of .Net Standard library and a .Net Framework application.
Open the .csproj
file of the .Net Framework project with a text editor. Inside the first PropertyGroup
add the line
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
Save the file, reopen Solution in Visual Studio and perform Clean & Build
.Net Framework projects use an old version of the .csproj
project files. References/Dependencies are stored in the additional packages.config
file. By default, building a .Net Framework project makes the system to search for a packages.config
file in the referenced projects. If no such file is found, the build task treats the referenced project as having no dependencies. Therefore, in the example, the MongoDB.Driver library is not added.
By adding the proposed line in the .csproj
project file, the build task searches the project file of the referenced project for dependencies, where they are stored in .Net Standard project files.
.Net Core projects by default search for the newer project file structure.
The default behavior for new projects can be set in the Options -> NuGet -> General -> Package Management