成功发布后Asp.net 5 Web Application启动异常

时间:2016-01-12 04:18:36

标签: visual-studio asp.net-core dnx50

我有一个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()




我已经搜索了高低解决方案。我无法弄清楚我缺少什么依赖。我试过了

  

删除package.lock.json

     

dnu restore

这是我的项目的dnx配置设置: enter image description here

以下是发布的设置:

enter image description here

有人可以读这些茶叶吗?

3 个答案:

答案 0 :(得分:1)

美好的一天。我们很少遇到这种类型的错误。它常常指向缺少的组件(最常见的组件)。检查所有必要的参考,设置为Copy Local - >是的,大部分时间都有帮助。如果程序集/引用设置为Copy Local - >则不会将其包含在发布中。假的。

希望这有帮助。

答案 1 :(得分:1)

只是为了它,我将“将源文件编译成Nuget包”设置为false。现在它有效。

enter image description here

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

答案 2 :(得分:0)

此错误与位于项目目录中的global.json文件(不是解决方案一)有关。如果要使用编译选项发布项目,请务必将其添加到publishExclude

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