0

I am trying to write some pretty basic MVC Controller code to read in a file in a direcory located in a wwwroot sub folder.

When I add this code to my controller:

String path = HttpContext.Current.Server.MapPath("~/Data/data.html");

VS tells me that HttpContext is available in "Microsoft.AspNet.Http.Abstractions": "1.0.0-beta5-11495" so using Visual Studio's quick helper I choose the option to add it to the project.json file. It also adds this using statement to my controller class.

using Microsoft.AspNet.Http;

Then all heck breaks out because while HttpContext resolves the 'Current' property does not. Furthermore, adding that package breaks the Startup.cs code because the IApplicationBuild parameter in the Configure method cannot be resolved because VS says:

The type 'IApplicationBuilder' exists in both 
'Microsoft.AspNet.Http.Abstractions, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null' and 
'Microsoft.AspNet.Http, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null'   
VS_MVCWebApp.DNX 4.5.1

Maybe I am not doing this right at all using the new dnx framework and if that is the case what is the correct approach?

At the end of the day I would like to just read in a file in my controller using 1.0.0-beta4 of he dnx451 framework.

Thanks for any help you can provide.

4

1 回答 1

0

检查您的软件包版本。我只是通过将所有有问题的 .NET nuget 包更改为“1.0.0-*”来解决此错误。如果有的话,请确保对类库项目执行相同的操作。

例如,在我的情况下,我有一个使用 Microsoft.AspNet.Http 的“业务”类库和使用相同的测试类库,所以只要确保它们都有“1.0.0-*”的版本

更新:请忽略之前的评论,因为这只会引用最新的可用包,这显然会产生很多问题!

我设法通过在我的解决方案中的所有项目中引用相同的包来解决这个问题。还要确保当您在 MVC 项目中引用一个项目并且该项目正在使用 Microsoft.AspNet.Http(例如它包含一个中间件)时,请确保该项目引用的是 Microsoft.AspNet.MVC 而不是 Microsoft.ASPNET。网址。

这也给我运行 xunit 测试带来了问题。检查此问题以获取更多信息xUnit.net v2 not found .NET Core Tests in Visual Studio 2015

于 2015-05-30T18:01:25.737 回答