项目“XXXXXX”没有锁定文件。请运行“dotnet restore”以生成新的锁定文件

时间:2016-09-20 16:29:55

标签: asp.net-core asp.net-core-mvc asp.net-core-1.0 coreclr asp.net-core-webapi

我有ASP.NET Core Web API项目和.Net Core Library项目。 Web API将库项目引用为target : project。库项目的名称是Transformations 下面是两个项目的project.json

Project.json for Web API

"dependencies": {
   "Microsoft.NETCore.App": {
    "version": "1.0.0",
    "type": "platform"
  },
   "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
   "Microsoft.AspNetCore.Mvc": "1.0.0",
   "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
   "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
   "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
   "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
   "Microsoft.Extensions.Configuration.Json": "1.0.0",
   "Microsoft.Extensions.Logging": "1.0.0",
   "Microsoft.Extensions.Logging.Console": "1.0.0",
   "Microsoft.Extensions.Logging.Debug": "1.0.0",
   "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
   "Transformations": {
            "target": "project"
    },
   "Microsoft.Extensions.DependencyInjection": "1.0.0",
   "Serilog.Extensions.Logging": "1.3.0-dev-10125",
   "Serilog.Sinks.RollingFile": "3.0.0",
   "Serilog.Settings.Configuration": "2.1.0",
   "Microsoft.AspNetCore.Diagnostics": "1.0.0"
},

project.json for Library project

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  },
  "configurations": {
    "Production": {},
    "Staging": {}
  }
}

在下面的构建服务器上是Api&的项目结构。转型项目。

 D:\Jenkins\MyJenkinsProject\workspace\src\MySolution
                                                   \Api
                                                   \Transformation

在构建服务器上,我执行了以下命令

  D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet restore

然后

  D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet build

我收到错误

  

项目转换没有锁定文件。请跑   “dotnet restore”生成一个新的锁定文件。

现在,如果我按顺序运行以下命令,那么一切正常。

  D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Transformation>dotnet restore
  D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet restore
  D:\Jenkins\MyJenkinsProject\workspace\src\MySolution\Api>dotnet build

问题
1>当库作为API项目中的项目引用时,为什么我需要单独为库项目运行dotnet restore?为什么不能隐含地restores推荐项目?

2 个答案:

答案 0 :(得分:3)

From Zlatko Knezevic

  

此行为是设计使然。 [...]如果您希望一次性恢复所有项目的所有依赖项,可以这么说,只需在解决方案的根目录下运行dotnet restore(您拥有global.json文件)。

答案 1 :(得分:-2)

我相信你可以直接做dotnet build。它应该自动执行dotnet restore