gpt4 book ai didi

c# - Asp vnext IServiceCollection 存在于两个命名空间

转载 作者:可可西里 更新时间:2023-11-01 03:11:25 26 4
gpt4 key购买 nike

今天我创建了一个新的空 vnext web 项目并开始遵循本指南:http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6

当我尝试添加时:

using Microsoft.Framework.DependencyInjection;

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

我收到一条错误消息:

The type 'IServiceCollection' exists in both 'Microsoft.Framework.DependencyInjection.IServiceCollection, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'Microsoft.Framework.DependencyInjection.Interfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

我一直在尝试 aspnet.mvc 的不同测试版,我从 project.json 中删除了 aspnetcore50(因为它已经为我解决了之前的问题)。我也尝试指定要使用的命名空间,但没有解决任何问题。现在我不知道如何解决这个问题。

我的项目.json

{
"webroot": "wwwroot",
"version": "1.0.0-*",
"exclude": [
"wwwroot"
],
"packExclude": [
"node_modules",
"bower_components",
"**.kproj",
"**.user",
"**.vspscc"
],
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
"Microsoft.AspNet.Mvc": "6.0.0-beta4-12857"
},
"frameworks" : {
"aspnet50" : { }
}
}

有没有人遇到同样的错误并解决了?

最佳答案

为什么不使用显式引用public void ConfigureServices(Microsoft.Framework.DependencyInjection.IServiceCollection services)

或者您可能需要像这样使用别名

using DI = Microsoft.Framework.DependencyInjection;

然后

public void ConfigureServices(DI.IServiceCollection services)
{
services.AddMvc();
}

关于c# - Asp vnext IServiceCollection 存在于两个命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28696226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com