1)从 https://github.com/aspnet/home 签出代码并进入文件夹 samples/latest/HelloMvc/ ;
2)运行命令 dnu restore 恢复nuget包包;
3)运行命令 dnx . kestrel 启动HelloMvc程序,出现下面的错误:
System.InvalidOperationException: No service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment' has been registered. at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService (IServiceProvider provider, System.Type serviceType) [0x00000] in :0 at Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService[IApplicationEnvironment] (IServiceProvider provider) [0x00000] in :0 at Microsoft.AspNet.Hosting.WebHostBuilder.Build () [0x00000] in :0 at Microsoft.AspNet.Hosting.Program.Main (System.String[] args) [0x00000] in :0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
请问如何解决这个问题?
换成 samples/1.0.0-beta4/HelloMvc/ ,可以正常运行。
看来是dnx的版本与HelloMvc不匹配。
两种解决方法
1. 是你说的办法
2. 首先,添加 <add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/api/v2/" /> 到你的nuget feed里。
然后运行dnvm upgrade -u 更新你的dnvm到最新的unstable版本,目前应该是1.0.0-beta6-11944
最后重新运行dnu restore (如果package没有更新,需要加上-no--cache)