jeudi 3 décembre 2020

Why are some of a dependent project's dependencies not being copied to bin directory?

I have an application (console) which targets .NET 4.7 using MSVC 2019 and which references a lot of NuGet packages.

When I build, those packages end up in the bin/Debug (or bin/Release) folder -- so the application can use them at run-time, which is good/expected.

Then I want to unit-test it. So I create a *.Tests project, in the same solution, which references the application project. After a rebuild, some but not all of the application's packages are in the test project's bin/Debug folder. The test project therefore fails to load various application classes (because the packages they depend on aren't present at run-time).

  • Why are some of the packages missing?
  • Why is it only some of them?
  • How to correct it?

I can correct it by declaring that the test project itself depends directly on all the same packages as the application under test. But my impression was that shouldn't be necessary.


For reference, here's an example of an exception due to a missing reference:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'Foo.Tests.MyClass' threw an exception.

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.

Here are the files present in the Test project's bin/Debug directory.

The Test project depends on nothing except the application under test, so all these result are here because they're dependencies of the application under test.

Microsoft.Bcl.AsyncInterfaces.dll
Microsoft.Bcl.AsyncInterfaces.xml
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.DependencyInjection.Abstractions.xml
Microsoft.Extensions.Hosting.Abstractions.dll
Microsoft.Extensions.Hosting.Abstractions.xml
Microsoft.Extensions.Hosting.dll
Microsoft.Extensions.Hosting.xml
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Logging.Abstractions.xml
Microsoft.Extensions.Logging.dll
Microsoft.Extensions.Logging.xml
Microsoft.Extensions.Options.dll
Microsoft.Extensions.Options.xml
netstandard.dll
Newtonsoft.Json.dll
Newtonsoft.Json.xml
NLog.config
NLog.dll
NLog.Extensions.Logging.dll
NLog.Extensions.Logging.xml
NLog.xml
System.Data.SQLite.dll
System.Data.SQLite.xml
System.Threading.Tasks.Extensions.dll
System.Threading.Tasks.Extensions.xml
Topshelf.dll
Topshelf.xml

Here is the much longer list of files which are present in the bin/Debug folder of the application under test.

Autofac.Configuration.dll
Autofac.Configuration.pdb
Autofac.Configuration.xml
Autofac.dll
Autofac.pdb
Autofac.xml
Microsoft.Bcl.AsyncInterfaces.dll
Microsoft.Bcl.AsyncInterfaces.xml
Microsoft.Extensions.Configuration.Abstractions.dll
Microsoft.Extensions.Configuration.Abstractions.xml
Microsoft.Extensions.Configuration.Binder.dll
Microsoft.Extensions.Configuration.Binder.xml
Microsoft.Extensions.Configuration.CommandLine.dll
Microsoft.Extensions.Configuration.CommandLine.xml
Microsoft.Extensions.Configuration.dll
Microsoft.Extensions.Configuration.EnvironmentVariables.dll
Microsoft.Extensions.Configuration.EnvironmentVariables.xml
Microsoft.Extensions.Configuration.FileExtensions.dll
Microsoft.Extensions.Configuration.FileExtensions.xml
Microsoft.Extensions.Configuration.Json.dll
Microsoft.Extensions.Configuration.Json.xml
Microsoft.Extensions.Configuration.UserSecrets.dll
Microsoft.Extensions.Configuration.UserSecrets.xml
Microsoft.Extensions.Configuration.xml
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.DependencyInjection.Abstractions.xml
Microsoft.Extensions.DependencyInjection.dll
Microsoft.Extensions.DependencyInjection.xml
Microsoft.Extensions.FileProviders.Abstractions.dll
Microsoft.Extensions.FileProviders.Abstractions.xml
Microsoft.Extensions.FileProviders.Physical.dll
Microsoft.Extensions.FileProviders.Physical.xml
Microsoft.Extensions.FileSystemGlobbing.dll
Microsoft.Extensions.FileSystemGlobbing.xml
Microsoft.Extensions.Hosting.Abstractions.dll
Microsoft.Extensions.Hosting.Abstractions.xml
Microsoft.Extensions.Hosting.dll
Microsoft.Extensions.Hosting.xml
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Logging.Abstractions.xml
Microsoft.Extensions.Logging.Configuration.dll
Microsoft.Extensions.Logging.Configuration.xml
Microsoft.Extensions.Logging.Console.dll
Microsoft.Extensions.Logging.Console.xml
Microsoft.Extensions.Logging.Debug.dll
Microsoft.Extensions.Logging.Debug.xml
Microsoft.Extensions.Logging.dll
Microsoft.Extensions.Logging.EventLog.dll
Microsoft.Extensions.Logging.EventLog.xml
Microsoft.Extensions.Logging.EventSource.dll
Microsoft.Extensions.Logging.EventSource.xml
Microsoft.Extensions.Logging.xml
Microsoft.Extensions.Options.ConfigurationExtensions.dll
Microsoft.Extensions.Options.ConfigurationExtensions.xml
Microsoft.Extensions.Options.dll
Microsoft.Extensions.Options.xml
Microsoft.Extensions.Primitives.dll
Microsoft.Extensions.Primitives.xml
Microsoft.Win32.Primitives.dll
netstandard.dll
Newtonsoft.Json.dll
Newtonsoft.Json.xml
NLog.config
NLog.dll
NLog.Extensions.Logging.dll
NLog.Extensions.Logging.xml
NLog.xml
System.AppContext.dll
System.Buffers.dll
System.Buffers.xml
System.Collections.Concurrent.dll
System.Collections.dll
System.Collections.NonGeneric.dll
System.Collections.Specialized.dll
System.ComponentModel.Annotations.dll
System.ComponentModel.dll
System.ComponentModel.EventBasedAsync.dll
System.ComponentModel.Primitives.dll
System.ComponentModel.TypeConverter.dll
System.Console.dll
System.Data.Common.dll
System.Data.SQLite.dll
System.Data.SQLite.xml
System.Diagnostics.Contracts.dll
System.Diagnostics.Debug.dll
System.Diagnostics.EventLog.dll
System.Diagnostics.EventLog.xml
System.Diagnostics.FileVersionInfo.dll
System.Diagnostics.Process.dll
System.Diagnostics.StackTrace.dll
System.Diagnostics.TextWriterTraceListener.dll
System.Diagnostics.Tools.dll
System.Diagnostics.TraceSource.dll
System.Diagnostics.Tracing.dll
System.Drawing.Primitives.dll
System.Dynamic.Runtime.dll
System.Globalization.Calendars.dll
System.Globalization.dll
System.Globalization.Extensions.dll
System.IO.Compression.dll
System.IO.Compression.ZipFile.dll
System.IO.dll
System.IO.FileSystem.dll
System.IO.FileSystem.DriveInfo.dll
System.IO.FileSystem.Primitives.dll
System.IO.FileSystem.Watcher.dll
System.IO.IsolatedStorage.dll
System.IO.MemoryMappedFiles.dll
System.IO.Pipes.dll
System.IO.UnmanagedMemoryStream.dll
System.Linq.dll
System.Linq.Expressions.dll
System.Linq.Parallel.dll
System.Linq.Queryable.dll
System.Memory.dll
System.Memory.xml
System.Net.Http.dll
System.Net.NameResolution.dll
System.Net.NetworkInformation.dll
System.Net.Ping.dll
System.Net.Primitives.dll
System.Net.Requests.dll
System.Net.Security.dll
System.Net.Sockets.dll
System.Net.WebHeaderCollection.dll
System.Net.WebSockets.Client.dll
System.Net.WebSockets.dll
System.Numerics.Vectors.dll
System.Numerics.Vectors.xml
System.ObjectModel.dll
System.Reflection.dll
System.Reflection.Extensions.dll
System.Reflection.Primitives.dll
System.Resources.Reader.dll
System.Resources.ResourceManager.dll
System.Resources.Writer.dll
System.Runtime.CompilerServices.Unsafe.dll
System.Runtime.CompilerServices.Unsafe.xml
System.Runtime.CompilerServices.VisualC.dll
System.Runtime.dll
System.Runtime.Extensions.dll
System.Runtime.Handles.dll
System.Runtime.InteropServices.dll
System.Runtime.InteropServices.RuntimeInformation.dll
System.Runtime.Numerics.dll
System.Runtime.Serialization.Formatters.dll
System.Runtime.Serialization.Json.dll
System.Runtime.Serialization.Primitives.dll
System.Runtime.Serialization.Xml.dll
System.Security.Claims.dll
System.Security.Cryptography.Algorithms.dll
System.Security.Cryptography.Csp.dll
System.Security.Cryptography.Encoding.dll
System.Security.Cryptography.Primitives.dll
System.Security.Cryptography.X509Certificates.dll
System.Security.Principal.dll
System.Security.Principal.Windows.dll
System.Security.Principal.Windows.xml
System.Security.SecureString.dll
System.Text.Encoding.dll
System.Text.Encoding.Extensions.dll
System.Text.Encodings.Web.dll
System.Text.Encodings.Web.xml
System.Text.Json.dll
System.Text.Json.xml
System.Text.RegularExpressions.dll
System.Threading.dll
System.Threading.Overlapped.dll
System.Threading.Tasks.dll
System.Threading.Tasks.Extensions.dll
System.Threading.Tasks.Extensions.xml
System.Threading.Tasks.Parallel.dll
System.Threading.Thread.dll
System.Threading.ThreadPool.dll
System.Threading.Timer.dll
System.ValueTuple.dll
System.ValueTuple.xml
System.Xml.ReaderWriter.dll
System.Xml.XDocument.dll
System.Xml.XmlDocument.dll
System.Xml.XmlSerializer.dll
System.Xml.XPath.dll
System.Xml.XPath.XDocument.dll
Topshelf.dll
Topshelf.xml

Here's the difference, i.e. the files which are present in one but not in the other.

Autofac.Configuration.dll
Autofac.Configuration.pdb
Autofac.Configuration.xml
Autofac.dll
Autofac.pdb
Autofac.xml
Microsoft.Extensions.Configuration.Abstractions.dll
Microsoft.Extensions.Configuration.Abstractions.xml
Microsoft.Extensions.Configuration.Binder.dll
Microsoft.Extensions.Configuration.Binder.xml
Microsoft.Extensions.Configuration.CommandLine.dll
Microsoft.Extensions.Configuration.CommandLine.xml
Microsoft.Extensions.Configuration.dll
Microsoft.Extensions.Configuration.EnvironmentVariables.dll
Microsoft.Extensions.Configuration.EnvironmentVariables.xml
Microsoft.Extensions.Configuration.FileExtensions.dll
Microsoft.Extensions.Configuration.FileExtensions.xml
Microsoft.Extensions.Configuration.Json.dll
Microsoft.Extensions.Configuration.Json.xml
Microsoft.Extensions.Configuration.UserSecrets.dll
Microsoft.Extensions.Configuration.UserSecrets.xml
Microsoft.Extensions.Configuration.xml
Microsoft.Extensions.DependencyInjection.dll
Microsoft.Extensions.DependencyInjection.xml
Microsoft.Extensions.FileProviders.Abstractions.dll
Microsoft.Extensions.FileProviders.Abstractions.xml
Microsoft.Extensions.FileProviders.Physical.dll
Microsoft.Extensions.FileProviders.Physical.xml
Microsoft.Extensions.FileSystemGlobbing.dll
Microsoft.Extensions.FileSystemGlobbing.xml
Microsoft.Extensions.Logging.Configuration.dll
Microsoft.Extensions.Logging.Configuration.xml
Microsoft.Extensions.Logging.Console.dll
Microsoft.Extensions.Logging.Console.xml
Microsoft.Extensions.Logging.Debug.dll
Microsoft.Extensions.Logging.Debug.xml
Microsoft.Extensions.Logging.EventLog.dll
Microsoft.Extensions.Logging.EventLog.xml
Microsoft.Extensions.Logging.EventSource.dll
Microsoft.Extensions.Logging.EventSource.xml
Microsoft.Extensions.Options.ConfigurationExtensions.dll
Microsoft.Extensions.Options.ConfigurationExtensions.xml
Microsoft.Extensions.Primitives.dll
Microsoft.Extensions.Primitives.xml
Microsoft.Win32.Primitives.dll
System.AppContext.dll
System.Buffers.dll
System.Buffers.xml
System.Collections.Concurrent.dll
System.Collections.dll
System.Collections.NonGeneric.dll
System.Collections.Specialized.dll
System.ComponentModel.Annotations.dll
System.ComponentModel.dll
System.ComponentModel.EventBasedAsync.dll
System.ComponentModel.Primitives.dll
System.ComponentModel.TypeConverter.dll
System.Console.dll
System.Data.Common.dll
System.Diagnostics.Contracts.dll
System.Diagnostics.Debug.dll
System.Diagnostics.EventLog.dll
System.Diagnostics.EventLog.xml
System.Diagnostics.FileVersionInfo.dll
System.Diagnostics.Process.dll
System.Diagnostics.StackTrace.dll
System.Diagnostics.TextWriterTraceListener.dll
System.Diagnostics.Tools.dll
System.Diagnostics.TraceSource.dll
System.Diagnostics.Tracing.dll
System.Drawing.Primitives.dll
System.Dynamic.Runtime.dll
System.Globalization.Calendars.dll
System.Globalization.dll
System.Globalization.Extensions.dll
System.IO.Compression.dll
System.IO.Compression.ZipFile.dll
System.IO.dll
System.IO.FileSystem.dll
System.IO.FileSystem.DriveInfo.dll
System.IO.FileSystem.Primitives.dll
System.IO.FileSystem.Watcher.dll
System.IO.IsolatedStorage.dll
System.IO.MemoryMappedFiles.dll
System.IO.Pipes.dll
System.IO.UnmanagedMemoryStream.dll
System.Linq.dll
System.Linq.Expressions.dll
System.Linq.Parallel.dll
System.Linq.Queryable.dll
System.Memory.dll
System.Memory.xml
System.Net.Http.dll
System.Net.NameResolution.dll
System.Net.NetworkInformation.dll
System.Net.Ping.dll
System.Net.Primitives.dll
System.Net.Requests.dll
System.Net.Security.dll
System.Net.Sockets.dll
System.Net.WebHeaderCollection.dll
System.Net.WebSockets.Client.dll
System.Net.WebSockets.dll
System.Numerics.Vectors.dll
System.Numerics.Vectors.xml
System.ObjectModel.dll
System.Reflection.dll
System.Reflection.Extensions.dll
System.Reflection.Primitives.dll
System.Resources.Reader.dll
System.Resources.ResourceManager.dll
System.Resources.Writer.dll
System.Runtime.CompilerServices.Unsafe.dll
System.Runtime.CompilerServices.Unsafe.xml
System.Runtime.CompilerServices.VisualC.dll
System.Runtime.dll
System.Runtime.Extensions.dll
System.Runtime.Handles.dll
System.Runtime.InteropServices.dll
System.Runtime.InteropServices.RuntimeInformation.dll
System.Runtime.Numerics.dll
System.Runtime.Serialization.Formatters.dll
System.Runtime.Serialization.Json.dll
System.Runtime.Serialization.Primitives.dll
System.Runtime.Serialization.Xml.dll
System.Security.Claims.dll
System.Security.Cryptography.Algorithms.dll
System.Security.Cryptography.Csp.dll
System.Security.Cryptography.Encoding.dll
System.Security.Cryptography.Primitives.dll
System.Security.Cryptography.X509Certificates.dll
System.Security.Principal.dll
System.Security.Principal.Windows.dll
System.Security.Principal.Windows.xml
System.Security.SecureString.dll
System.Text.Encoding.dll
System.Text.Encoding.Extensions.dll
System.Text.Encodings.Web.dll
System.Text.Encodings.Web.xml
System.Text.Json.dll
System.Text.Json.xml
System.Text.RegularExpressions.dll
System.Threading.dll
System.Threading.Overlapped.dll
System.Threading.Tasks.dll
System.Threading.Tasks.Parallel.dll
System.Threading.Thread.dll
System.Threading.ThreadPool.dll
System.Threading.Timer.dll
System.ValueTuple.dll
System.ValueTuple.xml
System.Xml.ReaderWriter.dll
System.Xml.XDocument.dll
System.Xml.XmlDocument.dll
System.Xml.XmlSerializer.dll
System.Xml.XPath.dll
System.Xml.XPath.XDocument.dll

Aucun commentaire:

Enregistrer un commentaire