c# – Visual Studio replacing dependency with a different version


I have a Visual Studio solution that consists of multiple projects like so:

  • Models – contains POCOs and ORM. Built on .NET Framework 4.8
  • Services – contains business logic. Built on .NET Core 3.1

Services project references Models.

Models project references a NuGet package, PetaPoco.Compiled (version 6.0.677.0).

Building the solution should copy PetaPoco.dll from the Models/bin directory to the Services/bin directory. VS 2019 and VS 2017 exhibit this expected behavior.

However Visual Studio 2022 pulls a different copy of the PetaPoco.dll from somewhere (the GAC?) that is a different version (version 6.0.683.0) and target framework (.NETStandard v2.1 vs .Net Framework v4.5).

I can confirm this by comparing the DLL in the Models/bin with the Services/bin in dotPeek:

Screenshot of differences between DLL

The version of the PetaPoco DLL that Visual Studio builds with is incompatible with our codebase, so the app throws an exception as soon as it tries to make a call to the PetaPoco DLL.

If I manually copy the expected DLL into the Services/bin directory and start the app, it works fine.

I’ve done the basic troubleshooting stuff (uninstalled/reinstalled the NuGet package, verified there is not a binding redirect for that package, rebooted/restarted VS 2022).

How can I get VS 2022 to use the version of the DLL that’s output to the Models/bin directory and not replace it with something else?

Leave a Reply

Your email address will not be published. Required fields are marked *