【问题标题】:Cant Run Default ASP.NET Web App In Visual Studio Code for Mac无法在 Visual Studio Code for Mac 中运行默认 ASP.NET Web 应用程序
【发布时间】:2015-11-26 07:45:49
【问题描述】:

刚刚在 Mac 上使用 Visual Studio Code 启动 ASP.NET 项目

我已经完成了所有常规步骤,以成功完成的dnu restore 命令结束。

然后我运行 dnx web 并得到一个正在运行的 localhost:5000 - 但是当我浏览到该地址时没有内容。

在终端窗口中,我可以看到下面的错误(很抱歉,我没有将其全部包含在内,因为它非常冗长)。

info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
      User profile is available. Using '/Users/deanchalk/.local/share/ASP.NET/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNet.Hosting.Internal.HostingEngine[1]
      Request starting HTTP/1.1 GET http://localhost:5000/  
info: Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker[1]
      Executing action method firstmacaspnetapp.Controllers.HomeController.Index with arguments () - ModelState is Valid'
fail: Microsoft.AspNet.Diagnostics.ExceptionHandlerMiddleware[0]
      An unhandled exception has occurred: Unable to resolve service for type 'Microsoft.Dnx.Compilation.ILibraryExporter' while attempting to activate 'Microsoft.AspNet.Mvc.Razor.Compilation.RoslynCompilationService'.
      System.InvalidOperationException: Unable to resolve service for type 'Microsoft.Dnx.Compilation.ILibraryExporter' while attempting to activate 'Microsoft.AspNet.Mvc.Razor.Compilation.RoslynCompilationService'.
        at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites (Microsoft.Extensions.DependencyInjection.ServiceProvider provider, ISet`1 callSiteChain, System.Reflection.ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) [0x00000] in <filename unknown>:0 
        at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite (Microsoft.Extensions.DependencyInjection.ServiceProvider provider, ISet`1 callSiteChain) [0x00000] in <filename unknown>:0 
        at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite (IService service, ISet`1 callSiteChain) [0x00000] in <filename unknown>:0 
        at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite (System.Type serviceType, ISet`1 callSiteChain) [0x00000] in <filename unknown>:0 
        at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites (Microsoft.Extensions.DependencyInjection.ServiceProvider provider, ISet`1 callSiteChain, System.Reflection.ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) [0x00000] in <filename unknown>:0 
        at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite (Microsoft.Extensions.DependencyInjection.ServiceProvider provider, ISet`1 callSiteChain) [0x00000] in <filename unknown>:0  

我用谷歌搜索了一下,找不到任何信息。

我的 project.json 看起来像这样:

{
  "version": "1.0.0-*",
  "userSecretsId": "aspnet5-firstmacaspnetapp-88915393-5f54-4e2d-9285-912b92370fb0",
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "tooling": {
    "defaultNamespace": "firstmacaspnetapp"
  },

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc1-final",
    "EntityFramework.SQLite": "7.0.0-rc1-final",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
    "Microsoft.Dnx.Runtime":"1.0.0-rc1-final",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
  },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules",
    "bower_components"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [
      "npm install",
      "bower install",
      "gulp clean",
      "gulp min"
    ]
  }
}

有人有什么想法吗?

【问题讨论】:

  • 我在 Windows 上使用 Visual Studio 时遇到了同样的错误。在我的情况下,我不小心在 rc2 运行时使用所有 rc1 包运行我的项目。切换运行时后一切正常。也许你也有类似的问题。

标签: asp.net asp.net-mvc visual-studio visual-studio-code


【解决方案1】:

类型

dnvm 列表

在您的项目文件夹中时进入终端。然后检查你的 project.json 中的所有项目,看看是否列出了正确的依赖版本。

然后运行

dnu 恢复

这在 OSX 上为我解决了这个问题。

【讨论】:

  • 啊伙计——你的想法看起来很有希望,但是当我设法把所有东西都放在正确的版本上时,它根本没有任何区别。无论如何,谢谢 - 如果你有任何其他想法,我将不胜感激 - 我想做的就是在我的 mac 上获取 asp.net 站点,事实证明这是一项不可能完成的任务
  • 它在我的 Mac 上运行 :) 你能检查一下 dnvm list 在你的 Mac 上返回什么吗?
  • stackoverflow.com/questions/34201252/…@af0l 你能检查一下吗?
【解决方案2】:

所以,当我在我的 Mac 上设置我的 asp.net 项目时,我也遇到了这个错误。我通过升级 Mono 来修复它(如果那是您正在使用的库。如果您正在使用它,则应该升级核心)。要升级,请从终端将其用于单声道:

dnvm 升级 -r 单声道

使用它从终端升级核心:

dnvm 升级 -r coreclr

然后我运行 dnu restore 只是为了确定,然后运行 ​​dnx web 并且我能够将其拉到 http://localhost:5000/

注意:我首先进行了所有其他升级,所以这可能是最后一个问题(如果你明白我的意思的话)。不过值得一试,它对我有用。

【讨论】:

    猜你喜欢
    • 2015-07-09
    • 2017-11-26
    • 2021-06-30
    • 2022-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 1970-01-01
    相关资源
    最近更新 更多