7

我有一个 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 恢复

这是我的项目的 dnx 配置设置: 在此处输入图像描述

这是发布的设置:

在此处输入图像描述

谁能读懂这些茶叶?

4

3 回答 3

1

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

希望这可以帮助。

于 2016-01-21T01:57:52.353 回答
1

只是为了它,我将“将源文件编译到 Nuget 包”设置为 false。现在它可以工作了。

在此处输入图像描述

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

于 2016-01-21T03:45:34.153 回答
0

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

"publishExclude": [
  "**.user",
  "**.vspscc",
  "global.json"
],
于 2016-04-07T19:38:56.390 回答