1

I've installed a new package on an existing project.enter image description here

The problem is it's detecting a different version of the Microsoft.Build.Framework. I got Version=17.5.0 for both Microsoft.Build and Microsoft.Build.Framework but it's seeing Version=15.1.0.0.

I have the updated version of NuGet (Version 6.5.0) which is compatible with my Visual Studio (Version 17.5.5) which according to this answer should fix it.

I've also restarted Visual Studio and tried again, which should also fix it according to this answer.

Is there something more going on under the hood here?

Prosy Arceno
  • 2,616
  • 1
  • 8
  • 32

2 Answers2

2

Microsoft.Build.Locator solved my issue.

To ensure that programmatic builds from your application match builds done within Visual Studio or MSBuild.exe, you might need to load the same version of the MSBuild assemblies that were installed with a specific version of Visual Studio and use the same SDKs that are available within that version of Visual Studio. Or, when you're creating a build application that will be run on machines that might have various installed versions of MSBuild, .NET, and Visual Studio, you might also want to find and use a consistent version of MSBuild. The Microsoft.Build.Locator API streamlines this process.

Prosy Arceno
  • 2,616
  • 1
  • 8
  • 32
  • 1
    Hi Prosy, since you verified and found the solution of the question, you can [mark this as the answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) to end this question. This will be beneficial to others when searching the issue in stackoverflow after meeting a similar issue . :) – Bowman Zhu-MSFT May 24 '23 at 09:33
1

Go to the /Obj folder and take a backup copy of your project.assets.json file.

Edit the project.assets.json file removing the json chunks/segments that refer to the v15.1.0.0.

Now try to install the v=17.5.0 reference and Visual Studio shouldn't get confused and load an old version.

If that fails you might want to delete your NuGet Cache using Visual Studio > Tools > Package Manager > Settings > click the Delete NuGet Packages button and then re-add the NuGet references via the Package Manager.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Both Microsoft Build and Build Framework reference the same updated version in the assets.json file. And clearing still produces the same error – Prosy Arceno May 15 '23 at 23:16
  • Did you delete all your Nuget and try and only get the latest? – Jeremy Thompson May 16 '23 at 01:30
  • No, I didn't want to update some packages as I am unsure if there will be some errors. But Microsoft Build and Build Framework are both updated to the latesst – Prosy Arceno May 16 '23 at 01:51