DisplayMode / DiplayMode提供程序问题Asp.Net MVC 4

时间:2012-03-27 09:03:50

标签: asp.net-mvc-4

我最近一直在尝试MVC 4。从开发人员预览开始,现在是测试版。

一切都运作良好,但我想利用内置的缩小和放大压缩功能。但似乎它没有出现在开发人员预览中,因为无论我尝试什么代码都不会编译/提供干净的运行,如果我添加任何捆绑相关。然后我做了一些研究并看到了MVC 4 beta。

我卸载了mvc 4并使用beta安装程序重新安装了它。创建了一个新项目,它使用捆绑运行良好。但无论我做了什么,(包括将dll从新解决方案复制到我的旧解决方案。)我无法在现有解决方案中使用捆绑工具

在global.asax.cs文件中

[1]

BundleTable .Bundles.RegisterTemplateBundles();

捆绑表甚至不会注册。 (获得红色下划线)

[2]

我尝试了其他方法只是为了验证新dll是否正在使用。

以前要检查显示模式,将使用以下内容

[a]
    DisplayModes.Modes.Insert(0, new DefaultDisplayMode("iPhone")
    {
      ContextCondition = (context => context.Request.UserAgent.IndexOf
                         ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
    });

但它已更新为

[b]
    DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone")
    ...

如果我使用[a]而不是[b],代码将编译,但它不会使用[a]给我一个干净的运行,因为它在运行时错误输出

无法从程序集'System.Web.WebPages,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'加载类型'System.Web.WebPages.DisplayModes'。

难道我的旧解决方案仍然以某种方式引用旧dll,即使我复制了新的dll,删除了引用并手动将它们指向新的?


@Brad Christie提出的参考条目

<Reference Include="EntityFramework">
  <HintPath>..\packages\EntityFramework.4.1.10331.0\lib\net40\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="System.Json, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\System.Json.4.0.20126.16343\lib\net40\System.Json.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\System.Net.Http.2.0.20126.16343\lib\net40\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\System.Net.Http.Formatting.4.0.20126.16343\lib\net40\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\System.Net.Http.2.0.20126.16343\lib\net40\System.Net.Http.WebRequest.dll</HintPath>
</Reference>
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetWebPages.Core.2.0.20126.16343\lib\net40\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetWebApi.Core.4.0.20126.16343\lib\net40\System.Web.Http.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\System.Web.Http.Common.4.0.20126.16343\lib\net40\System.Web.Http.Common.dll</HintPath>
</Reference>
<Reference Include="System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetWebApi.4.0.20126.16343\lib\net40\System.Web.Http.WebHost.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetMvc.4.0.20126.16343\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Optimization">
  <HintPath>..\packages\Microsoft.Web.Optimization.1.0.0-beta\lib\net40\System.Web.Optimization.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetRazor.Core.2.0.20126.16343\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetWebPages.Core.2.0.20126.16343\lib\net40\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetWebPages.Core.2.0.20126.16343\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\AspNetWebPages.Core.2.0.20126.16343\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>

3 个答案:

答案 0 :(得分:2)

我把它添加到我的班级并使其正常工作:

using System.Web.WebPages;

答案 1 :(得分:1)

不是我希望的答案,但它完成了工作。我最终创建了一个新的解决方案,并将我的代码移动到它。似乎要做的伎俩。不确定为什么以前的解决方案没有正确更新:/

尝试使用解决方案资源管理器,右键单击根解决方案并检查属性。在共同属性下 - &gt;项目依赖项,确保检查相关项目。

答案 2 :(得分:0)

我遇到了同样的问题,需要1天才能解决这个问题。 我检查了一切(装配参考/更换装配)。

最后卸载 asp .net网页并重新安装,这样可行。

希望这会有所帮助