dotnet / dotnet/msbuild

.NET Framework application should automatically use NuGet packages from referenced class libraries

Open
#2,558 0 comments 3 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

A .NET framework (version 4.6.1) VB console project references (via project reference) a .NET Framework (version 4.6.1) class library. The NuGet packages referenced by the class library (via `PackageReference`) are not restored in the console application which results in a `DllNotFoundException`.

According to this [article by Scott Hanselman](https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx), as well as issues on GitHub (e.g. #1582 ), there are problems when combining .NET Standard and .NET Framework. However, in this example the class library as well as console application both target .NET Framework 4.6.1.

## Reproduce Error by

Clone [this repository](https://github.com/suchja/nuget-references-problem), build the solution and run it. I do get an `TypeInitializationException` with an inner exception of type `DllNotFoundException`.

Comparing the output folder of the console application `NuGetRefTest` with the class library output folder `LibWithRef` shows that some assemblies are missing while others are available.

Available (in output folder of class library and console app):

- Emgu.CV.UI.dll
- Emgu.CV.World.dll
- ZedGraph.dll

Missing (from console app, but available in class library):

- Emgu.CV.UI.GL.dll
- OpenTK.dll
- OpenTK.GLControl.dll
- x64/cvextern.dll
- x64/opencv_ffmpeg310_64.dll
- x86/cvextern.dll
- x86/opencv_ffmpeg310.dll

## Workarounds

1. Add NuGet package to console application (while keeping it in class library as well). - This works and solves the problem, but is not what I expect to see.
2. Add `PackageReference` to the console application's csproj file. - Rebuilding and running it shows the same error.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.