DEV Community

Cover image for Microsoft.NET.Sdk.Common.targets was not found
Jozef Chmelar
Jozef Chmelar

Posted on

7 2

Microsoft.NET.Sdk.Common.targets was not found

After update of Visual Studio and .NET I got an error that seems to repeat pretty often. Unfortunately I forget how to deal with it every single time.

The issue looks like this

msbuild //works
dotnet build
Enter fullscreen mode Exit fullscreen mode

Results in following error

C:\Program Files\dotnet\sdk\5.0.41\Current\SolutionFile\ImportAfter\Microsoft .NET.Sdk.Solution.targets(14,3): error MSB4619: The imported
project "C:\Program Files\dotnet\sdk\5.6.100\Sdks\Microsoft .NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" was not found. Confirm that
the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.41\Sdks\Microsoft.NET.Sdk\targets\Microsoft .NET.Sdk.Common.targets" is correct, and that the file exists on disk.

Build FAILED.

C:\Program Files\dotnet\sdk\5.0.41\Current\SolutionFile\ImportAfter\Microsoft .NET.Sdk.Solution.targets(14,3): error MSB4619: The imported
project "C:\Program Files\dotnet\sdk\5.6.100\Sdks\Microsoft .NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" was not found. Confirm that
the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.41\Sdks\Microsoft.NET.Sdk\targets\Microsoft .NET.Sdk.Common.targets" is correct, and that the file exists on disk.
Enter fullscreen mode Exit fullscreen mode

When you try to print the file Microsoft.NET.Sdk.Solution.targets

cat "C:\Program Files\dotnet\sdk\5.0.401\Current\SolutionFile\ImportAfter\Microsoft.NET.Sdk.Solution.targets"
Enter fullscreen mode Exit fullscreen mode

Notice this line

  <Import Project="$(MSBuildSDKsPath)\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" />
Enter fullscreen mode Exit fullscreen mode

The MSBuildSDKsPath variable is important here. It looks like it's looking at the wrong folder.

When I created an enviroment variable with the name MSBuildSDKsPath and value C:\Program Files\dotnet\sdk\5.0.401\Sdks it works!

Don't forget to restart your terminal.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay