将dnvm更新为1.0.0-rc1-final后出错

时间:2015-11-19 12:32:32

标签: c# asp.net dnvm

将dnvm从beta8更新为1.0.0-rc1-final后,我的Startup.cs出错:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc(); <======= "iservicecollection does not contain a definition for add mvc(error)"
        services.AddTransient<IRepository, MongoRepository>();
    }

我的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"
  ]
}

我做错了什么?谢谢。如果我只是评论行:

services.AddMvc();

我遇到了这个错误:http://clip2net.com/clip/m446898/72b2d-clip-21kb.png?nocache=1

2 个答案:

答案 0 :(得分:2)

Microsoft.Framework库现在是Microsoft.Extensions

例如,Microsoft.Framework.CodeGenerators.Mvc现在是Microsoft.Extensions.CodeGenerators.Mvc

我希望这会有所帮助。

答案 1 :(得分:0)

继续关注乔尔的回答:

我刚遇到这个问题。

在命令提示符下,我运行dnvm upgrade来更新我的DNX。

注意:确保运行此工作室时关闭visual studio。我把它打开了,只是在我做了下面的事情后才会工作。因为它我有IApplicationBuilder exists in both Microsoft.AspNet.Http.Abstractions and Microsoft.AspNet.Http错误。所以我最终重新启动我的电脑,然后一切正常。所以也许重新启动电脑,然后执行以下操作。

将其全部切换到rc1-final版本。

我将global.json更改为:

{
  "projects": [ "src" ],
  "sdk": {
    "version": "1.0.0-rc1-final"
  }
}

我的project.json依赖项部分如下所示:

"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"
},

请注意Microsoft.Extensions.DependencyInjection,而不是Microsoft.Framework

右键点击&#39;参考&#39;并选择恢复包&#39;。在任何project.json更改之后执行此操作。

然后在我的Startup.cs文件中,我将引用从Microsoft.Framework更改为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();
    }

}