MVC 4/Razor 中的可移植类库与 Visual Studio 2012 RC? [英] Portable Class Library in MVC 4 / Razor with Visual Studio 2012 RC?

查看:30
本文介绍了MVC 4/Razor 中的可移植类库与 Visual Studio 2012 RC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从使用 Visual Studio 2012 RC 以来,我们在剃刀视图中使用便携式类库(.net 4.5 和 Metro 配置文件)中的类时会收到 HttpCompileException.

since working with Visual Studio 2012 RC we get an HttpCompileException when using a class out of an portable class library (.net 4.5 & metro profile) within a razor view.

例外:(德语到英语在谷歌上翻译,抱歉)

Exception: (german to english translated on google, sorry)

System.Web.HttpCompileException (0x80004005):     
c:UsersuserAppDataLocalTempTemporary ASP.NET        
Files
oot1995167a126b7c4dApp_Web_index.cshtml.1fbcdbb1.zaniprm5.0.cs(29):

error CS0012: The type 'System.Object' is not in a referenced assembly is 
defined. Add a reference to the Assembly "System.Runtime, Version = 4.0.0.0, 
Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" added.   

at
System.Web.Compilation.AssemblyBuilder.Compile()   
System.Web.Compilation.BuildProvidersCompiler.PerformBuild()    
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
...

解决方案结构:

  • 便携式类库(.net 4.5 和 Metro 配置文件)
    • 公共类用户{ ... }
    • 参考可移植类库
    • Razor-View
      • @model 用户

      由于 Visual Studio 2012 RC 不再可能添加引用System.Runtime".

      Since Visual Studio 2012 RC adding reference "System.Runtime" is not possible any more.

      推荐答案

      在 ViewsWeb.config 文件中,在 部分下添加以下代码:

      In the ViewsWeb.config file, add the following code under the <system.web> section:

      <compilation debug="true" targetFramework="4.5">
          <assemblies>
              <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
          </assemblies>
      </compilation>
      

      您可能还需要引用许多其他程序集,具体取决于您的可移植代码使用的类型.您可以在遇到错误时添加每个程序集,也可以在 C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5Facades.

      There are a bunch of other assemblies you may also need to reference, depending on what types your portable code is using. You can either add each one as you encounter the error, or add the full list of assemblies in C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5Facades.

      这篇关于MVC 4/Razor 中的可移植类库与 Visual Studio 2012 RC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆