在ASP.Net应用程序中使用MVC6的依赖冲突

时间:2016-10-18 07:30:03

标签: c# asp.net-mvc dependencies entity-framework-6

这可能是依赖冲突吗?我收到了错误。我已经尝试更改依赖项,但它仍然会重新发现这些错误,请我支持你。 这是project.json文件

"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
    "Microsoft.AspNet.Mvc": "6.0.0-beta5",
    "EntityFramework.SqlServer": "7.0.0-beta5",
    "EntityFramework.Commands": "7.0.0-beta5",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta8"
  },

这是StartUp.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.Framework.DependencyInjection;

using MyQuotesApps.models;
using Microsoft.Framework.Runtime;
using Microsoft.Framework.Configuration;
using Microsoft.AspNet.Hosting;

namespace MyQuotesApps
{
    public class Startup
    {
        public IConfiguration Configuration { get; set; }
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
            services.AddEntityFramework().AddSqlServer()
                .AddDbContext<QuotesAppContext>(options =>options.UseSqlServer(Configuration["Data:ConnectionString"]));
        }

        public Startup(IHostingEnvironment env, IApplicationEnvironment appenv) {
            var configurationBuilder = new ConfigurationBuilder(appenv.ApplicationBasePath);
            configurationBuilder.AddJsonFile("config.json");
            configurationBuilder.AddEnvironmentVariables();
            Configuration = configurationBuilder.Build();
        }

        public void Configure(IApplicationBuilder app)
        {
            app.UseMvc();
        }
    }
}

这将返回以下错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from 'string' to 'Microsoft.Framework.Configuration.IConfigurationProvider'  MyQuotesApps.DNX 4.5.1, MyQuotesApps.DNX Core 5.0   C:\Users\ken4ward\documents\visual studio 2015\Projects\MyQuotesApps\src\MyQuotesApps\Startup.cs    28  Active
Error   CS1061  'EntityOptionsBuilder' does not contain a definition for 'UseSqlServer' and no extension method 'UseSqlServer' accepting a first argument of type 'EntityOptionsBuilder' could be found (are you missing a using directive or an assembly reference?)   MyQuotesApps.DNX 4.5.1, MyQuotesApps.DNX Core 5.0   C:\Users\ken4ward\documents\visual studio 2015\Projects\MyQuotesApps\src\MyQuotesApps\Startup.cs    24  Active

1 个答案:

答案 0 :(得分:0)

您必须迁移到ASP.net Core 1.0。如果您仍在使用测试版软件包,那么您将遇到大麻烦。因此开始迁移或使用最新软件包创建新项目。

您可以在此处查看如何迁移:Migration

或者从最新的.Net核心开始:.Net Core 1.0

Getting started with ASP.NET Core MVC and Visual Studio