Tag: Microsoft

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

    I’ve been updating Visual Studio and .NET versions and today while trying to build a project using Cake I got the error:

    C:\Program Files\dotnet\sdk\8.0.403\Current\SolutionFile\ImportAfter\Microsoft.NET.Sdk.Solution.targets(14,3): error MSB4019: The imported project "C:\Prog
    ram Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" was not found. Confirm that the expression in the Import decl
    aration "C:\Program Files\dotnet\sdk\8.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" is correct, and that the file exists on disk.
    An error occurred when executing task 'Restore'.
    Error: One or more errors occurred. (.NET CLI: Process returned an error (exit code 1).)
            .NET CLI: Process returned an error (exit code 1).

    When looking closely the error is actually quite self-explanatory and simple to fix. If we check the file Microsoft.NET.Sdk.Common.targets:

    cat "C:\Program Files\dotnet\sdk\8.0.403\Current\SolutionFile\ImportAfter\Microsoft.NET.Sdk.Solution"

    We’ll be able to notice that the imported project path is built using the environment variable MSBuildSDKsPath which in my case was pointing to version 8.01.00 of .NET while I had 8.0.403 installed.

    <Import Project="${MSBuildSDKsPath}\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.Common.targets" />

    The solution was simply to edit the MSBuildSDKsPath environment variable path to the correct path (C:\Program Files\dotnet\sdk\8.0.403\Sdks), restarting the terminal, run Cake again and voilá!