.Net 4.8 C# Api project, consists of one main project and 5 attached class library projects.
I need to add functionality to one of the class library projects to be able to access a value stored in Azure KeyVault.
So I have added the
<package id="Azure.Security.KeyVault.Secrets" version="4.1.0" targetFramework="net48" />
NuGet package to my class library solution.
In turn this also adds 9 other Nuget packages to the class library solution: System.Memory
, System.Threading.Tasks.Extensions
, System.ValueTuple
to name a few.
Also 7 of these assemblyIdentity references are also added to the main web.config of the main project. In the form of below:
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
So am I right in guessing the main project knows these are being added to an attached project, so also add them to the web.config of the main.
However, these 7 references are also added to the app.config of my attached unit test project.
My question is why have they been added to the unit test project? Why is this?
They shouldnt be needed? am I missing something?
Any explaination would be very helpful in understanding. I dont want to commit any refs to this project that arnt needed??
When you add a NuGet package to a project, it often brings along its dependencies, which are other packages that it relies on to function properly. These dependencies are necessary for the package you added to work correctly.
In your case, when you added the Azure.Security.KeyVault.Secrets package to your class library project, it brought along its dependencies such as System.Memory, System.Threading.Tasks.Extensions, and System.ValueTuple, among others.
Regarding why these dependencies are also added to your main project's web.config and your unit test project's app.config, it's important to understand how the .NET runtime resolves assemblies at runtime.
The assemblies listed in your web.config file are binding redirects. They ensure that when your application is running, the correct versions of these assemblies are loaded, even if a different version is referenced by a dependency. This is important for ensuring compatibility and preventing version conflicts.
Similarly, your unit test project's app.config file may also contain binding redirects to ensure that the correct versions of assemblies are loaded when running your unit tests.
These binding redirects are automatically added by Visual Studio when you add a NuGet package to your project because it detects that the added package has dependencies that need to be resolved at runtime.
So, to answer your question, these dependencies are added to both your main project and your unit test project because they are needed for your application and tests to run correctly. Removing them could potentially lead to runtime errors or unexpected behavior if any of the dependencies are missing. Therefore, it's generally best practice to leave them in place unless you have a specific reason to remove them.