“预期的锁定文件不存在。请在我完成后立即运行”dnu restore“

时间:2015-09-28 08:42:23

标签: c# json asp.net-core dnx entity-framework-core

我正在为所有内容运行beta7,包括EF 7.我正在尝试使用ASP.NET 5应用程序模板项目连接到我的远程现有数据库。我的project.json看起来像这样:

{
  "webroot": "wwwroot",
  "userSecretsId": "aspnet5-XXX-409e9e37-b7bb-4185-b7aa-6dc336087524",
  "version": "1.0.0-*",

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-beta7",
    "EntityFramework.SqlServer": "7.0.0-beta7",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
    "Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
    "Microsoft.AspNet.Mvc": "6.0.0-beta7",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
    "Microsoft.Framework.Logging": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta7",
    "Microsoft.Framework.Logging.Debug" : "1.0.0-beta7",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],

  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],

  "scripts": {
   "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  }
}

在线搜索似乎为了完成我想要的操作,我需要运行以下命令:

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer

我无法做到,因为我遇到的问题已解决,如下所述: Using existing database with ASP.NET 5 and EF7 (beta 7)

现在我终于可以运行命令“dnx”,但是当我尝试使用我的connectionstring运行它时,看起来像这样:

dnx ef dbcontext scaffold "Data Source=192.168.XX.XXX\devsql;Initial
Catalog=Development;Integrated Security=False;User ID=system;Password=XXX;"
EntityFramework.SqlServer

它给了我以下错误:

[ERROR] dnx : System.InvalidOperationException: Failed to resolve the
following dependencies for target framework 'DNXCore,Version=v5.0':
[ERROR] En línea: 1 Carácter: 1 [ERROR] + dnx ef dbcontext scaffold
"Data Source=192.168.XX.XXX\devsql;Initial Catalog=Dev ... [ERROR] +
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR]     + CategoryInfo          : NotSpecified:
(System.InvalidO...,Version=v5.0'::String) [], RemoteException [ERROR]
+ FullyQualifiedErrorId : NativeCommandError [ERROR]   [ERROR]    EntityFramework.Commands 7.0.0-beta7 [ERROR]   
EntityFramework.SqlServer 7.0.0-beta7 [ERROR]   
Microsoft.AspNet.Authentication.Cookies 1.0.0 [ERROR] -beta7 [ERROR]  
Microsoft.AspNet.Authentication.Facebook 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Authentication.Google 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Authentication.MicrosoftAccount 1.0.0-beta7 [ERROR]  
Microsoft.AspNet.Authentication.Twitter 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Diagnostics 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Diagnostics.Entity 7.0.0-beta7 [ERROR]   
Microsoft.AspNet.Identity.EntityFramework 3.0.0-beta7 [ERROR]   
Microsoft.AspNet.Mvc 6.0.0-beta7 [ERROR]   
Microsoft.AspNet.Mvc.TagHelpers 6.0.0-beta7 [ERROR]   
Microsoft.AspNet.Server.IIS 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Server.WebListener 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.StaticFiles 1.0.0-beta7 [ERROR]   
Microsoft.AspNet.Tooling.Razor 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Configuration.Abstractions 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Configuration.Json 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Configuration.UserSecrets 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Logging 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Logging.Console 1.0.0-beta7 [ERROR]   
Microsoft.Framework.Logging.Debug 1.0.0-beta7 [ERROR]   
Microsoft.VisualStudio.Web.BrowserLink.Loader 14.0.0-beta7 [ERROR] 
[ERROR]
C:\XXX\XXX\src\XXX\project.lock.json(1,0):
error: The expected lock file doesn't exist. Please run "dnu restore"
to generate a new lock file. [ERROR] Current runtime target framework:
'DNXCore,Version=v5.0 (dnxcore50)' [ERROR]  Version:     
1.0.0-beta7-15532 [ERROR]  Type:         CoreCLR [ERROR]  Architecture: x64 [ERROR]  OS Name:      Windows [ERROR]  OS Version: 
6.1 [ERROR]  [ERROR]    at Microsoft.Dnx.Runtime.DefaultHost.GetEntryPoint(String
applicationName) [ERROR]    at
Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host,
String applicationName, String[] args) [ERROR]    at
Microsoft.Dnx.ApplicationHost.Program.Main(String[] args) [ERROR] ---
End of stack trace from previous location where exception was thrown
--- [ERROR]    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [ERROR]
at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly
assembly, String[] args, IServiceProvider serviceProvider) [ERROR]   
at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args,
IRuntimeEnvironment env, FrameworkName targetFramework) [ERROR]    at
Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args,
FrameworkName targetFramework) [ERROR]    at
Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args,
FrameworkName targetFramework) [ERROR]

鉴于

[ERROR]
C:\XXX\XXX\src\XXX\project.lock.json(1,0):
error: The expected lock file doesn't exist. Please run "dnu restore"
to generate a new lock file.

我试过了

PS C:\XXX\XXX> dnu restore
Microsoft .NET Development Utility CoreCLR-x64-1.0.0-beta7-15532

CACHE https://api.nuget.org/v3/index.json Restoring packages for
C:\XXX\XXX\src\XXX\project.json   CACHE
https://api.nuget.org/v3-flatcontainer/system.threading.threadpool/index.json
GET
https://api.nuget.org/v3-flatcontainer/system.net.sockets/index.json  
OK
https://api.nuget.org/v3-flatcontainer/system.net.sockets/index.json
1117ms Writing lock file
C:\XXX\XXX\src\XXX\project.lock.json Restore
complete, 2071ms elapsed

NuGet Config files used:
    C:\Users\XXX\AppData\Roaming\NuGet\NuGet.Config
    C:\XXX\XXX\NuGet.Config

Feeds used:
    https://api.nuget.org/v3-flatcontainer/

成功重新创建了project.lock.json,似乎(时间戳也反映了这一点)。但是,当我再次尝试运行我的脚手架脚本时,它会一直显示上面显示的相同错误,包括“预期的锁定文件不存在”部分。

知道出了什么问题吗?

6 个答案:

答案 0 :(得分:37)

我遇到了同样的问题,并通过以下方式修复: - 右键点击“参考文献” - 选择“恢复包”

或Ctrl + Shilf + R

它将创建/更新“project.lock.json”文件,其中包含应用程序正在使用的所有NuGet包的完整列表。在我看来,你不应该把它放在源代码控制

答案 1 :(得分:4)

试试这个:

关闭 Visual Studio 完全

打开 Visual Studio命令提示符窗口

cd C:\XXX\XXX\src\XXX\

dnu restore

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer

答案 2 :(得分:1)

如果在当前在Windows Server内核环境中执行的应用程序上运行此命令,则Core 5.0将无法正常运行。它可以读取一些,但不能创建,特别是如果您在IIS中托管。我有很多这个问题,我发现最好只跳过主依赖中的EntityFramework.Commands,然后跳转到

"frameworks":{
    "dnx451":{
          "dependencies":{
                 "EntityFramework.Commands":"7.0.0-beta7"
          }
      }
  ,"dnxcore50"...

另外,确保当你准备好运行dnx时,运行

dnvm use latest -r clr -arch {your server kernel arch} x64|x86

确保您不会尝试为命令调用coreclr。应该解决这个问题,它在生产服务器上对我有用(因为脚手架dbcontext在很大程度上是无害的)

答案 3 :(得分:1)

我有同样的问题,尝试删除引用并重新添加它们但它失败了。 我去了ManageNugetPackage管理器并从设置中删除了私有内部nuget资源并恢复了我的包,它工作了(我还删除了旧的project.lock文件)

答案 4 :(得分:0)

我发现如果您在UNC路径上创建visual studio解决方案文件夹,则会发生此错误。

在虚拟机上使用Windows时,UNC路径通常会映射您的Documents文件夹(例如Parallels for Mac),因此默认情况下,visual studio将使用此路径作为新解决方案。

要解决此问题,我将visual studio解决方案文件夹移至虚拟机磁盘驱动器,然后重新打开该项目。

答案 5 :(得分:0)

我和VS 2015有类似的问题抱怨AspNetCore引用的恢复失败以及指向执行“dotnet恢复”的错误消息之一。在最后一步中,dotnet恢复失败。但是,

有效的解决方案是使用Nuget包管理器设置删除本地nuget包提要参考。