net core 3.0 (and higher) publish project with wrong dependencies
net core 3.0 (and higher) publish project with wrong dependencies
I have console project ProblemMainApp.
It has dependencies from Helper and Newtonsoft.Json 12.0.2.
Helper.csproj depend from Microsoft.Extensions.Configuration.Json 2.0.1.
Microsoft.Extensions.Configuration.Json 2.0.1 depend from Newtonsoft.Json 10.0.1.

I publish project with command:
dotnet publish -c Debug -f netcoreapp2.0 --force -r centos.7-x64 -o D:\Publish\test
If I have installed netcore 2.* on my comp, that in output folder have Newtonsoft.Json 12.0.2.
But if I have installed netcore 3.* on my comp, that in output folder have Newtonsoft.Json 10.0.1 and program not working. I need to add a reference to Newtonsoft.Json 12.0.2 in Helper.csproj, even though it's not needed.
@jeffschwMSFT
cc @livarcocc
@nguerrera @dsplaisted can one of you take a look?
@blacksnake-rus Can you share the output of dotnet --info from a machine where this is failing?
I wasn't able to repro this with a preview of the 3.1.100 SDK.
Can you try publishing without overriding the output folder and seeing if you still encounter the issue?
Thanks
Can you share the output of dotnet --info from a machine where this is failing?
The problem is reproduced not only on my machine (if necessary, I can provide information on them).
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\
Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33
.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Can you try publishing without overriding the output folder and seeing if you still encounter the issue?
Without overriding the output folder issue not reproduced (Newtonsoft.Json version in out folder - 12.0.2)
Same problem.
Yeah, the problem is topical. When can me expect a solution?
I did some digging into this since I had the same issue, and with some of the context here, I think I've figured out what's going on. When you run dotnet publish on the solution level, what happens is that each project within the solution gets their own publish directory. When you redirect the output, there is now only a single output directory, so it just combines all the dll's from all the publish directories into one, so there will only be one version available. If you check the project level publish directories, you will notice that the dll's are different versions.
You can get around this by explicitly doing a dotnet publish on the specific project that you're trying to publish rather than being ambiguous.
You can get around this by explicitly doing a
dotnet publishon the specific project that you're trying to publish rather than being ambiguous.
This method works, BUT when a starting project is specified, only those projects to which the specified project refers are added to the output folder. My project uses DI, where I get all necessary dlls by scanning the folder and I don't need to explicitly specify the dependency on them in the project.
Having this same issue on 3.1.301 SDK. I updated a library called PathosChild/FluentNexus to a newer version but dotnet publish is still publishing the 1.0 version even though teh application si requesting 1.0.1. The app runs fine in VS and when you look at the directory of files it's running from it has the right dll. But if you package it single file (which I do) and then run that and look at what it extracts its the old version. I don't know where it's getting these files from.
I just had the same issue with 3.1.301 SDK on Linux. I upgraded a NuGet package and built the Release build using dotnet publish with PublishReadyToRun=true. The published application failed with a FileLoadException could not load assembly version for the updated NuGet package. Searching my project folders for the DLL, I found three copies in: bin\Release\netcoreapp3.1\linux-arm\publish - contains old version R2R obj\Release\netcoreapp3.1\linux-arm\R2R - contains old version R2R bin\Release\netcoreapp3.1\linux-arm - contains correct new version
If I delete the obj\Release folder and rebuild I get the correct version DLL and the application runs. So it appears that dotnet publish PublishReadyToRun=true does not correctly update the obj\Release\netcoreapp3.1\linux-arm\R2R folder when a NuGet package DLL version changes.
I hope this helps others who have this issue.
Had the same issue but i could fix it with clearing the nuget caches
dotnet nuget locals all --clear
dotnet nuget locals global-packages -c
and/or adding the DisableImplicitNuGetFallbackFolder Option in the .csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NLog" Version="4.7.3" />
...
</ItemGroup>
</Project>
Been having this issue again, it's essentially making my application unusable, I publish it, some dependency doesn't work, publish it again after somehow fixing it, another dependency doesn't work, app just endlessly crashes for my users. This is getting frustrating.
Been having this issue again, it's essentially making my application unusable, I publish it, some dependency doesn't work, publish it again after somehow fixing it, another dependency doesn't work, app just endlessly crashes for my users. This is getting frustrating.
Can you try publishing without overriding the output folder? It helped for me
Not sure what you mean by not overriding the output folder? You mean don't choose where the output goes and just let it do the default?
To me this issue was caused by one of the projects in my solution having a transitive dependency to an older version of Newtonsoft.Json and then dotnet publish indeterministically picked sometimes the old version and sometimes the newer (correct) version of the dll to the publish output folder. I fixed it by finding out the project that had the transitive dependency, then adding an explicit/direct PackageReference to the correct version.
Enabling packages.lock.json files for all projects helped to spot the problematic project - read more at https://devblogs.microsoft.com/nuget/enable-repeatable-package-restores-using-a-lock-file/
Not sure what you mean by not overriding the output folder? You mean don't choose where the output goes and just let it do the default?
Yes. Don't use "-o" key
I fixed it by finding out the project that had the transitive dependency, then adding an explicit/direct PackageReference to the correct version.
Yes. Direct PackageReference to the correct version in each project works, but it is not convenient and not properly.
Details are on https://github.com/dotnet/sdk/issues/11953
Details are on #15607