MVC6 ne Pouvez pas trouver application.UseStaticFiles() lors du Démarrage
Je suis à jouer autour de la nouvelle ASPNET 5 bêta à l'aide de la dernière version de Code de Visual Studio (v0.3). Je ne veux pas mettre la VS2015 RC sur ma machine de travail. J'ai un barebones (Hello World) MVC6 app qui je l'ai pris en cours d'exécution après comprendre les bases de la dn* outils de ligne de commande.
Maintenant, je veux me servir d'un fichier statique. J'ai ajouté de Microsoft.AspNet.StaticFiles à mon projet.fichier json et restauré les paquets.
Mon projet.json:
{
"version": "1.0.0-*",
"webroot": "wwwroot",
"exclude": [
"wwwroot"
],
"packExclude": [
"**.kproj",
"**.user",
"**.vspscc"
],
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:8080",
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:8080"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
}
}
Mon Démarrage.cs:
using Microsoft.AspNet.Builder;
using Microsoft.Framework.DependencyInjection;
namespace EmailViewer
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseErrorPage();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.UseWelcomePage();
}
}
}
Tout fonctionne bien jusqu'à ce que je comprennent app.UseStaticFiles() à quel point j'obtiens l'erreur suivante:
System.IO.FileLoadException: Could not load file or assembly 'EmailViewer' or one of its dependencies. General Exception (Exception from HRESULT: 0x80131500)
File name: 'EmailViewer' ---> Microsoft.Framework.Runtime.Roslyn.RoslynCompilationException: C:\src\fx5\EmailViewer\Startup.cs(16,13): error CS7069: Reference to type 'IApplicationBuilder' claims it is defined in 'Microsoft.AspNet.Http', but it could not be found
at Microsoft.Framework.Runtime.Roslyn.RoslynProjectReference.Load(IAssemblyLoadContext loadContext)
at Microsoft.Framework.Runtime.Loader.ProjectAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
at Microsoft.Framework.Runtime.Loader.ProjectAssemblyLoader.Load(AssemblyName assemblyName)
at dnx.host.LoaderContainer.Load(AssemblyName assemblyName)
at dnx.host.DefaultLoadContext.LoadAssembly(AssemblyName assemblyName)
at Microsoft.Framework.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
at Microsoft.Framework.Runtime.Loader.LoadContext.LoadAssemblyImpl(AssemblyName assemblyName)
at Microsoft.Framework.Runtime.Loader.LoadContext.TryLoadAssembly(LoadContext context, AssemblyName assemblyName, Assembly& assembly)
at Microsoft.Framework.Runtime.Loader.LoadContext.ResolveAssembly(Object sender, ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.AspNet.Hosting.Startup.StartupLoader.FindStartupType(String startupAssemblyName, IList`1 diagnosticMessages)
at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureStartup()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureApplicationServices()
at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start()
at Microsoft.AspNet.Hosting.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env)
at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args)
at dnx.host.RuntimeBootstrapper.Execute(String[] args)
Microsoft.Framework.Runtime.Roslyn.RoslynCompilationException: C:\src\fx5\EmailViewer\Startup.cs(16,13): error CS7069: Reference to type 'IApplicationBuilder' claims it is defined in 'Microsoft.AspNet.Http', but it could not be found
at Microsoft.Framework.Runtime.Roslyn.RoslynProjectReference.Load(IAssemblyLoadContext loadContext)
at Microsoft.Framework.Runtime.Loader.ProjectAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
at Microsoft.Framework.Runtime.Loader.ProjectAssemblyLoader.Load(AssemblyName assemblyName)
at dnx.host.LoaderContainer.Load(AssemblyName assemblyName)
at dnx.host.DefaultLoadContext.LoadAssembly(AssemblyName assemblyName)
at Microsoft.Framework.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
at Microsoft.Framework.Runtime.Loader.LoadContext.LoadAssemblyImpl(AssemblyName assemblyName)
at Microsoft.Framework.Runtime.Loader.LoadContext.TryLoadAssembly(LoadContext context, AssemblyName assemblyName, Assembly& assembly)
at Microsoft.Framework.Runtime.Loader.LoadContext.ResolveAssembly(Object sender, ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
J'ai essayé d'utiliser ces versions:
- 1.0.0-beta4
- 1.0.0-beta6-12114
Je ne peux pas comprendre ce que je fais mal. Des idées? Merci à l'avance!
OriginalL'auteur Gwendolyn Goetz | 2015-06-25
Vous devez vous connecter pour publier un commentaire.
Dans asp.net MVC6 rc1,
ajoutez la ligne suivante dans le projet.json "dépendances" de la section:
OriginalL'auteur ninetiger
Dans beta6/beta5, il a été modifié comme suit :
Également une mise à niveau à partir de la beta4 à beta5 n'est pas une chose aisée, mais c'est possible..
System.TypeLoadException: Could not load type 'Microsoft.AspNet.Http.PathString' from assembly 'Microsoft.AspNet.Http, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Veuillez vous assurer que vous avez inclus les directives nécessaires (en vs2015, Ctrl+. montre un potentiel fixe). Si ma solution a travaillé veuillez cocher cette solution comme réponse.
il y a un blog écrit par Miguel Alho, miguelalho.pt/mise à niveau-vnext-mvc6-apps-de-beta4-à-beta5 qui définit u dans le droit chemin.
Merci. Qu'il a fait.
Avec Beta8 il est d'application.UseStaticFiles() à nouveau
OriginalL'auteur Karthick
Dans ASP.NET MVC6 RC2, ajoutez la ligne suivante dans le projet.json "dépendances" de la section:
OriginalL'auteur Kelly Orr
Si votre .net de Base app utilise csproj ajouter la ligne suivante:
Ou exécutez la commande @Steve répertoriés:
OriginalL'auteur Justin
Changement, changement, ..., encore plus récent:
Ajouter à
project.json
dans des "dépendances" de la section:En Démarrage.cs, vous pouvez maintenant utiliser
merci @user1040323
OriginalL'auteur user1040323
Pour .net de base code de visual studio
ouvrir un terminal windows ou invite de commande dans le dossier racine du projet et d'installer le
Microsoft.AspNetCore.StaticFiles paquet
dotnet ajouter le package Microsoft.AspNetCore.StaticFiles
Pour Visual studio
ajouter de Microsoft.AspNetCore.StaticFiles package à l'aide de nuget
A fonctionné pour moi
OriginalL'auteur Steve
Pour VS 2017, j'ai installé à l'aide de NuGet manager mais
StaticFiles
était pas encore accessible. J'ai même supprimé et ré-ajoutée par l'édition de l' .csproj fichier XML (remplacement de JSON) mais j'ai pas encore accès. J'ai finalement résolu le problème en enregistrant le projet et le redémarrage VS 2017.OriginalL'auteur Kitson88
je pense que vous devez installer les fichiers statiques de la bibliothèque. Ouvrir package nuget et de recherche de fichiers statiques, vous trouverez de microsoft.owin.staticfiles de l'installer et il fonctionne.J'ai eu le même problème et après l'installation il a travaillé beaucoup.
OriginalL'auteur Ujjwal Kumar Gupta