Asp.net 5 成功发布后Web应用程序启动异常

Asp.net 5 Web Application startup exception after successful publish

我有一个 Asp.net 5 Web 应用程序,它在开发中运行良好(从 Visual Studio 或 VS 代码我可以毫无问题地启动)。但是,在成功发布应用程序后,当尝试使用“web.cmd”启动网站时,会出现以下错误并阻止网站加载:

Application startup exception: System.IO.FileNotFoundException: Could not load file or assembly 'my-ng2-website' or one of its dependencies. The system cannot find the file specified.
File name: 'my-ng2-website' ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
   at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)
   at System.Reflection.Assembly.LoadFile(String path)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadFile(String assemblyPath)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Host.LoaderContainer.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Host.DefaultLoadContext.LoadAssembly(AssemblyName assemblyName)
   at Microsoft.Dnx.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadAssemblyImpl(AssemblyName assemblyName)
   at Microsoft.Dnx.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.BuildApplication()

我到处寻找解决方案。我不知道我缺少什么依赖。我试过了

deleting the package.lock.json

dnu restore

这是我对项目的 dnx 配置设置:

发布设置如下:

有人能读懂这些茶叶吗?

美好的一天。我们很少遇到这种类型的错误。它经常指向缺少的程序集(最常见的程序集)。检查所有必要的引用,设置为 Copy Local -> true,在大多数情况下都有帮助。如果 assemblies/references 设置为 Copy Local -> false,则不会包含在发布中。

希望对您有所帮助。

为了好玩,我将 "Compile source files into Nuget Package" 设置为 false。现在可以了。

为什么会这样,我不知道。但希望这会帮助别人。

此错误与位于项目目录(不是解决方案目录)中的 global.json 文件有关。如果你想发布带有编译选项的项目,确保将它添加到 project.json

中的 publishExclude
"publishExclude": [
  "**.user",
  "**.vspscc",
  "global.json"
],