ASP。Net 5:更新1.0 Beta8到RC1—IServiceCollection中不包含AddMvc的定义

时间:2021-02-06 16:57:48

I have some code composed of an authorization api project,a common project and an ASP.net main application project, in a single solution. I have gone through the related project.json files and removed explicit beta8 references, and then made some other required corrections. For example, changing using Microsoft.Framework.Configuration to Microsoft.Extensions.Configuration, where necessary.

我有一些由授权api项目、公共项目和ASP.net主应用程序项目组成的代码,在一个解决方案中。我已经完成了相关的项目。json文件和删除了显式的beta8引用,然后进行了一些其他需要的修改。例如,使用Microsoft.Framework进行更改。Microsoft.Extensions配置。配置,在必要时。

I understand from the linked potential duplicate that the first thing to suspect is an invalid mixture of references in my various project.json files. I have no beta8 references left anywhere, explicitly. Thus I do not think that the linked issue is the same.

我从链接的潜在副本中了解到,首先要怀疑的是在我的不同项目中引用的无效混合。json文件。我没有明确的beta8引用。因此我不认为相关问题是相同的。

Where I'm stuck seems like a really basic thing:

我被困的地方似乎是最基本的东西:

Error   CS1061  Build   'IServiceCollection' does not contain a
definition for 'AddMvc' and no extension method 'AddMvc' accepting a first 
argument of type 'IServiceCollection' could be found (are you missing a 
using directive or an assembly reference?)  

I have Microsoft.AspNet.Mvc referenced in the project.json, and it doesn't matter if I put "using Microsoft.AspNet.mvc" in the .cs file or not the error persists. I thought you add references in the new world order, just by adding them to project.json. If an assembly reference exists in the project.json, why does this error still occur?

我有Microsoft.AspNet。项目中引用的Mvc。json,如果我使用" Microsoft.AspNet。在。cs文件中的mvc,错误将继续存在。我以为您只是通过将引用添加到project.json来添加新的世界顺序中的引用。如果项目中存在程序集引用。json,为什么这个错误还会发生?

My project.json:

我的project.json:

{
  "webroot": "wwwroot",
  "version": "1.0.0-*",

  "dependencies": {

    "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-*",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-*",
    "Microsoft.AspNet.Mvc": "6.0.0-*",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
    "Microsoft.AspNet.StaticFiles": "1.0.0-*",
    "Microsoft.Framework.Logging": "1.0.0-*",
    "Microsoft.Framework.Logging.Console": "1.0.0-*",
    "Microsoft.Framework.Logging.Debug": "1.0.0-*",
    "System.IdentityModel.Tokens": "5.0.0-*",
    "MyCompany.Common": "1.0.0-*"
  },

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

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

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

The line of code that's breaking is the AddMvc one:

正在崩溃的代码行是AddMvc:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using Microsoft.Extensions.Configuration;
using Microsoft.Dnx.Runtime;
using RamSoft.Authorization.Api.Common;
using System.IdentityModel.Tokens;
using Microsoft.AspNet.Authentication.JwtBearer;
using RamSoft.ITConsole.Common;
using Microsoft.Extensions.PlatformAbstractions;
namespace MyCompany.Authorization.Api
{
    public class Startup
    {
     ...
 public void ConfigureServices(IServiceCollection services)
        {
            services.AddInstance(_signingCredentials);
            services.AddInstance(_jwtBearerOptions);

            services.AddMvc();  // Fail.

        }
   ...
}

1 个解决方案

#1


0  

You need to change dependencies on your project. here is my project.json

您需要更改对项目的依赖关系。这是我project.json

"dependencies": {
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    }
  }

and adding using Microsoft.Extensions.Configuration; in startup.cs

使用Microsoft.Extensions.Configuration和添加;在startup.cs

we can use AddMvc() atleast working for Core 1.0 rc2

我们至少可以使用AddMvc()来处理核心1.0 rc2

#1


0  

You need to change dependencies on your project. here is my project.json

您需要更改对项目的依赖关系。这是我project.json

"dependencies": {
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview1-final",
      "type": "build"
    }
  }

and adding using Microsoft.Extensions.Configuration; in startup.cs

使用Microsoft.Extensions.Configuration和添加;在startup.cs

we can use AddMvc() atleast working for Core 1.0 rc2

我们至少可以使用AddMvc()来处理核心1.0 rc2