web-dev-qa-db-fra.com

"Le fichier de verrouillage attendu n'existe pas. Veuillez exécuter" dnu restore "" juste après l'avoir fait.

J'utilise la version bêta 7 pour tout, y compris EF 7. J'essaie de me connecter à ma base de données existante distante à l'aide du projet de modèle d'application ASP.NET 5. Mon projet.json ressemble à ceci:

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

En effectuant une recherche en ligne, il m'a semblé que pour exécuter ce que je voulais, il fallait exécuter la commande suivante:

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer

Ce que je ne pouvais pas faire parce que j'avais un problème qui a été résolu comme expliqué ici: Utilisation de la base de données existante avec ASP.NET 5 et EF7 (beta 7)

Maintenant, je peux enfin exécuter la commande "dnx", mais lorsque j'essaye de l'exécuter avec ma chaîne de connexion, qui ressemble à ceci:

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

cela me donne les erreurs suivantes:

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

Compte tenu du 

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

J'ai essayé de courir

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/

Ce qui recrée le projet.lock.json avec succès, semble-t-il (l’horodatage le reflète aussi). Cependant, lorsque j'essaie de réexécuter mon script d'échafaudage, il continue d'afficher la même erreur que celle indiquée ci-dessus, y compris la partie "Le fichier de verrouillage attendu n'existe pas".

Une idée de ce qui ne va pas?

23
Antrim

J'ai rencontré le même problème et je l'ai corrigé par: - Faites un clic droit sur "Références" - Sélectionnez "Restaurer les packages"

Ou Ctrl + Shilf + R

Il créera/actualisera le fichier "project.lock.json", qui comprend une liste complète de tous les packages NuGet utilisés par l'application. À mon avis, vous ne devriez pas le mettre dans le contrôle de source

37
Nhat Hong Ly

Essaye ça:

Fermer Visual Studio complètement.

Ouvrez une fenêtre d'invite de commande Visual Studio.

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

dnu restore

dnx ef dbcontext scaffold "ConnectionString" EntityFramework.SqlServer
4
Michael Rice

J'ai eu le même problème, j'ai essayé de supprimer les références et de les ajouter de nouveau, mais cela a échoué. fichier project.lock)

1
Vijaya Malla

Si vous exécutez cette commande sur une application en cours d'exécution dans un environnement Windows Server Kernel, Core 5.0 ne fonctionnera pas souvent. Il peut en lire, mais pas en créer, surtout si vous hébergez dans IIS. J'ai souvent eu ce problème, je trouvais préférable de simplement ignorer EntityFramework.Commands dans la dépendance principale et de passer à 

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

aussi, assurez-vous que lorsque vous êtes prêt à exécuter dnx, exécutez 

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

pour vous assurer que vous n'essayez pas d'appeler coreclr pour des commandes. cela devrait résoudre le problème, et il a pour moi sur un serveur de production (parce que l'échafaudage du dbcontext est en grande partie inoffensif)

1
Nathan Teague

J'ai constaté que si vous créez le dossier de solution Visual Studio sur un chemin UNC, cette erreur se produit.

Les chemins d'accès UNC mappent souvent votre dossier Documents lors de l'utilisation d'une fenêtre sur une machine virtuelle (par exemple, Parallels pour Mac) et Visual Studio utilisera donc ce chemin par défaut pour les nouvelles solutions.

Pour résoudre le problème, j'ai déplacé le dossier de la solution visual studio sur le lecteur de disque de la machine virtuelle, puis rouvert le projet.

0
wal5hy

J'avais un problème similaire avec VS 2015, se plaignant de l'échec de la restauration des références AspNetCore et de l'un des messages d'erreur pointant vers une "restauration du réseau de points". La restauration par dotnet a échoué au cours des dernières étapes. Mais,

La solution qui a fonctionné a été de supprimer les références de flux de paquets de nuget locales à l'aide des paramètres du gestionnaire de paquets de Nuget.

0
abhijoseph