DEV Community

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

Posted on

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.

Top comments (0)