.NET Core - Project version mismatch

by Matt Fantinel
03 Jun 2019 - 1 min read

This problem usually happens when you're working on a solution with multiple projects that were created using different versions of the .NET SDK.

The project was restored using Microsoft.NETCore.App version x.x.x, but with current settings, version y.y.y would be used instead

You may encounter this error when running dotnet build or maybe only on dotnet publish. In any case, the best way to get rid of this problem for good is the following:

  1. On the folder where your .sln file resides, create a new file named Directory.Build.props. If you're not working with a solution (not using Visual Studio), you can use create it on the root directory of your repository (usually where .gitignore is;
  2. With a text editor, add the following content to it:
Directory.Build.props
xml
<Project>
  <PropertyGroup>
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
    <GenerateFullPaths>true</GenerateFullPaths>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
</Project>

What these properties do is make your projects always restore and compile using the latest version available.

Try running the command again. If all went right, it should be compiling successfully now!

In case it doesn't work for you, you can add these lines manually on each of the .csproj files.

Thanks for reading!

Written by

Matt Fantinel

I’m a web developer trying to figure out this weird thing called the internet. I write about development, the web, games, music, and whatever else I feel like writing about!

About

Newsletter? I have it!

I have a newsletter as another way to share what I write on this blog. The main goal is to be able to reach people who don't use RSS or just prefer getting their articles delivered straight into their inbox.

  • No fixed frequency, but at least once at month;
  • I do not plan on having content exclusive to the newsletter. Everything on it will also be on the blog;
  • I will never, ever ever ever, send you any form of spam.

You might also like

View blog

MongoDB on Linux - Data directory /data/db not found

1 min read

Fix the error that occurs when trying to run freshly-installed MongoDB on a Linux machine.

Back-End
Read

.NET Core - Method not allowed on PUT and DELETE requests

2 min read

See how to solve this annoying error after deploying your .NET Core API.

Back-End
Read

Setting up Storybook on an Astro project

7 min read

I really, really thought this was gonna be easy.

Front-End
Read

Separating my website's content from its code

4 min read

Having an open source website is great, but having the content stored in the same spot as the code has some issues. On this post I walk through what I did to keep them separated.

Meta
Read