After updating dnvm from beta8
to 1.0.0-rc1-final
I had an error in my Startup.cs
:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(); <======= "iservicecollection does not contain a definition for add mvc(error)"
services.AddTransient<IRepository, MongoRepository>();
}
my project.json:
{
"packExclude": "*.cmd",
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
"Microsoft.AspNet.Hosting": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-*",
"Microsoft.Framework.ConfigurationModel.Json": "1.0.0-*",
"Microsoft.Framework.Logging": "1.0.0-*",
"Microsoft.Framework.Logging.Console": "1.0.0-*",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-*",
"Microsoft.Net.Http": "2.2.22",
"RestSharp": "105.2.3",
"mongocsharpdriver": "2.1.0"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5505",
"gen": "Microsoft.Framework.CodeGeneration",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Drawing": "4.0.0.0",
"System.Drawing.Design": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"bundleExclude": [
"node_modules",
"bower_components",
"**.kproj",
"**.user",
"**.vspscc"
]
}
What i did wrong? Thanks you. If i just comment line:
services.AddMvc();
I had this error: http://clip2net.com/clip/m446898/72b2d-clip-21kb.png?nocache=1
The Microsoft.Framework
libraries are now Microsoft.Extensions
.
For example, Microsoft.Framework.CodeGenerators.Mvc
is now Microsoft.Extensions.CodeGenerators.Mvc
I hope this helps.
Following on and expanding a bit on Joel's answer:
I just had this issue.
In the command prompt, i ran dnvm upgrade
to update my DNX.
NOTE : Make sure visual studio is closed when you run this. I had it open and it just would not work after i did the stuff below. I had a IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http
error because of it. So i ended up restarting my pc, and then everything worked. So maybe restart your pc, then do the following.
Switched it all to rc1-final
version.
I changed my global.json
to this:
{
"projects": [ "src" ],
"sdk": {
"version": "1.0.0-rc1-final"
}
}
My project.json
dependencies section looks like this:
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final"
},
Notice the Microsoft.Extensions.DependencyInjection
, not Microsoft.Framework
Right click on 'References' and select 'Restore Packages'. Do this after any project.json change.
Then in my Startup.cs
file, i changed the reference from Microsoft.Framework
to Microsoft.Extensions
:
using Microsoft.AspNet.Builder;
using Microsoft.Extensions.DependencyInjection;
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseMvc();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.