Cake 构建 DotNet Core 错误

Cake build DotNet Core error

我正在尝试使用 cake 使用 dotnet 核心构建我的解决方案,但我收到了它:

C:\Program Files\dotnet\sdk.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]

有什么问题吗?

如果我 运行 dotnet.exe 在 cmd 上构建,构建工作正常

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

环境机

我忘记了两件事。解决方案是:

  1. build.cake中设置正确的框架:

     var settings = new DotNetCoreBuildSettings
     {
         Framework = "netcoreapp1.1",
         Configuration = "Release",
         OutputDirectory = "./build/"
     };
    
     DotNetCoreBuild("./src/", settings);
    
  2. 使用 DotNetCoreRestore 恢复 NuGet 包 nuget.exe

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

结果是:

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