2
votes

I'm trying build my solution with dotnet core using cake but I receive it:

C:\Program Files\dotnet\sdk\1.0.1\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets(73,5): error : Project 'xxx.csproj' targets '.NETCoreApp,Version=v1.1'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v1.0'. [xxx.csproj]

What could be wrong?

If I run dotnet.exe build on cmd, the builds work normally

  • dotnet build xxx.csproj

Microsoft (R) Build Engine version 15.1.548.43366 Copyright (C) Microsoft Corporation. All rights reserved.

CouchDB.Driver.Core -> xxx.dll

Build succeeded. 0 Warning(s) 0 Error(s)

Time Elapsed 00:00:01.50

Environment Machine

  • The xxx.csproj version is:

    netcoreapp1.1

  • cake --version

    Version 0.19.1+Branch.main.Sha.4c5b4fd5b1c4d9d36066ec78714027e26b211af4

  • dotnet.exe --version

    1.0.1

  • dotnet.exe

    Microsoft .NET Core Shared Framework Host

    Version : 1.1.0 Build : 928f77c4bc3f49d892459992fb6e1d5542cb5e86

1
If you run with this stackoverflow.com/questions/38658660/… what dotnet command is actually being ran?Gary Ewan Park
How does your Cake script look? Are you using the MSBuild alias or DotNetCoreBuild one?devlead

1 Answers

4
votes

I forgot 2 things. The solution is:

  1. Set correct framework in build.cake:

     var settings = new DotNetCoreBuildSettings
     {
         Framework = "netcoreapp1.1",
         Configuration = "Release",
         OutputDirectory = "./build/"
     };
    
     DotNetCoreBuild("./src/", settings);
    
  2. Restore NuGet packages using the DotNetCoreRestore instead nuget.exe

    Task("Restore-NuGet-Packages")
    .IsDependentOn("Clean")
    .Does(() =>    {
         DotNetCoreRestore("src"); // use it instead of NuGetRestore("./folder");
    });
    

The result is:

Build
Executing task: Build
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

CouchDB.Driver.Core -> xxx.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:11.10
Finished executing task: Build