Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The expected lock file doesn't exist. Please run "dnu restore"" right after I have done so

I'm running beta7 for everything, including EF 7. I'm trying to connect to my remote existing database using the ASP.NET 5 Application template project. My project.json looks like this:

{
  "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" ]
  }
}

Doing a search online it seemed that in order to accomplish what I wanted I needed to run the following command:

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer

Which I could not do because I had an issue which was solved as explained here: Using existing database with ASP.NET 5 and EF7 (beta 7)

Now I can finally get to run the command "dnx", but when I try running it with my connectionstring, which looks like this:

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

it gives me the following errors:

[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]

Given the

[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.

I have tried running

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/

Which recreates the project.lock.json successfully, it seems (timestamp also reflects this). However, when I try running my scaffold script again, it keeps showing the same error shown above including the "expected lock file doesn't exist" part.

Any idea what's going wrong?

like image 382
Antrim Avatar asked Sep 28 '15 08:09

Antrim


3 Answers

I faced the same problem, and fixed it by: - Right click on "References" - Select "Restore Packages"

Or Ctrl + Shilf + R

It will create/update the "project.lock.json" file, which includes a complete list of all of the NuGet packages the app is using. In my opinion, you shouldn't put it in the source control

like image 55
Nhat Hong Ly Avatar answered Sep 20 '22 17:09

Nhat Hong Ly


Try this:

Close Visual Studio completely.

Open a Visual Studio Command Prompt window.

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

dnu restore

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer
like image 33
Michael Rice Avatar answered Sep 20 '22 17:09

Michael Rice


If you are running this command on an application currently executing in a Windows Server Kernel environment, Core 5.0 will not work often. It can read some, but not create, especially if you host in IIS. I had this issue a lot, I found it best to just skip EntityFramework.Commands in main dependency, and jump down to

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

also, make sure when you get ready to run dnx, run

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

to ensure you are not trying to invoke coreclr for commands. that should fix the issue, and it has for me on a production server (because scaffolding the dbcontext is largely harmless)

like image 20
Nathan Teague Avatar answered Sep 20 '22 17:09

Nathan Teague