I want to retrieve the NuGet dependency DLL's that are registered in the project package.config from the package folder.
package.config (sample):
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Humanizer.Core" version="2.6.2" targetFramework="net472" />
</packages>
Structure:
- Folder
- ProjectFolder
- packages.config <-- config file
- Packages
- Humanizer.Core.2.6.2
- lib
- netstandard1.0
- Humanizer.DLL
- netstandard2.0
- Humanizer.DLL
- Solution
Now I can retrieve information from the package.config
to get the id + version together to know in which folder I need to be in the Packages
folder. Then I am sure there is a lib
folder so that is fine to. But then I get stuck. Cause the lib
folder contains a netstandard1.0
and/or netstandard2.0
(or others) folder while the package.config had only a targetFramework="247"
attribute left that does not match.
Any idea how I should handle this? Maybe am doing it all wrong?
Get project dependency DLL's in package folder from package.json
Actually, I am confused why you get a targetframework="247"
. I wonder if it is changed by yourself.
So please run update-package -reinstall
under Tools-->NuGet Package Manager-->Package Manager Console to reinstall your nuget and dependencies.
targetframework
in packages.config
file means the framework version of your current project. It refers to the framework version of your current project. Install these nuget packages into the project under this framework version.
=======================================
Please note that:
When the nuget package install its dependencies, it is pursuing the rule Nearest wins. It will install the dependency which is nearer to the project's framework version.
You can check this document about how NuGet resolves package dependencies.
For an example, if your project is target to netframework4.7.2
and has dependencies like netframework 4.7.1
and netframework 4.6.2
, it will install the version of the dependency net framework4.7.1
that is closest to the main project net472
.
As your description, Humanizer.Core
has dependency like net standard 1.0
and netstandard 2.0
,
Also as this document said,
The minimum version supported by net standard 1.0
is net framework 4.5
and the minimum version supported by net standard 2.0
is net standard 4.6.1
.
===========================================================
If net framework 4.5
<= your main project framework version < net framework 4.6.1
.
The nuget package will install the dependency of net standard 1.0
.
If net framework 4.6.1
<= your main project framework version, the nuget package will install the dependency of net standard 2.0
.
If you have a newer version dependency and it is compatible with your main project, it will install the latest version.
Besides, you can upload your project and check on the hintpath
of the xxx.csproj
file to see which version of the dependency the project used.
If your project targets to >=net framework 4.6.1
, it will install the net standard 2.0
dependency.
========================
Test
And you can just create two projects which target to Net Framework4.5.2
and Net Framework 4.7.2
respectively. And then install this package in these two projects to see the behavior.