简体   繁体   中英

How .Net/VisualStudio handles having projects dependencies each with different nuget target for same nuget packages

I have a web service project in .Net 4.6.1 let's call it Project X , which has 2 project references(both class libs), let's call them Project A and B .

A has this in packages.config:

<package id="NLog" version="4.5.3" targetFramework="net35" />

While X and B has this in their packages.config:

<package id="NLog" version="4.5.3" targetFramework="net461" />

Now when I ran this command in project X's solution:

Update-Package –reinstall nlog -ignoreDependencies

And further, I build X's solution, and then run X. Now i want to know will code flows in project X using project A or B work fine for any nlog based logging they have inside code of A or B?

If answering this will need more explanation then request to please share any reference link which will help me understand this kind of setup and nuget target resolution for client app referring dependencies with a different nuget target for given nuget package.

Thanks

Edit:

IMHO The suggested question as this being duplicate of is not valid as that talks about scenarios when solution has projects with different nuget versions, which is not my case.

As my question is about both projects having same nuget version but different targetFramework.

Like for A it is targetFramework="net35", while for B and X it is targetFramework="net461".

But all 3 projects A,B and X using same version ie 4.5.3. Sorry the config i had earlier given showed versions as different but that wasn't my intention to talk about hence have edited to make version same.

So question is again how a project referring 2/more projects dependencies each of those using same version but different targetFramework gets addressed during build/execution of client app ie X here.

Is it like X will have nuget dll with highest targetFramework picked up and copied to it's bin? if not what happens then?

Is it like X will have nuget dll with highest targetFramework picked up and copied to it's bin? if not what happens then?

The project X will have nuget .Net 461 dll picked up and copied to it's bin, but not because of the highest targetFramework. That because the project X reference the nuget package NLog directly with target framework 461.

You can change MSBuild project build output verbosity to Normal or above, Tools->Options->Projects and Solutions->Build and Run->MSBuild project build output verbosity. In the output window, you can notice that the NLog.dll under the net45 copy to the project x bin folder:

在此处输入图片说明

And the NLog.dll under the net35 copy to the project A bin folder:

在此处输入图片说明

To check more info about this issue, I recommend you can check following thread:

MSBuild doesn't copy references (DLL files) if using project dependencies in solution

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM