在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
我用Google搜索,找不到任何信息。
我的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"
]
}
}
有没有人有任何想法?
答案 0 :(得分:0)
类型
dnvm list
在项目文件夹中进入终端。然后检查project.json以获取所有项目,以查看是否列出了依赖项的正确版本。
然后运行
dnu restore
这在OSX上为我解决了。
答案 1 :(得分:0)
所以,当我在Mac上设置我的asp.net项目时,我也遇到了这个错误。我通过升级Mono来修复它(如果那是您正在使用的库。如果您使用的话,应该升级Core)。要升级,请将其用于终端的单声道:
dnvm upgrade -r mono
使用此命令从终端升级核心:
dnvm upgrade -r coreclr
我然后运行dnu restore
只是为了确保然后dnx web
我能够在http://localhost:5000/
注意:我首先进行了所有其他升级,所以这可能是最后一个问题(如果你知道我的意思)。值得一试,它对我有用。