使用Visual Studio 2012 RC的MVC 4/Razor中的可移植类库?
自从使用Visual Studio 2012 RC后,我们在剃须刀视图中使用便携式类库(.net 4.5 & metro配置文件)中的类时遇到了HttpCompileException。使用Visual Studio 2012 RC的MVC 4/Razor中的可移植类库?
例外:(德语到英语翻译对谷歌,对不起)
System.Web.HttpCompileException (0x80004005):
c:\Users\user\AppData\Local\Temp\Temporary ASP.NET
Files\root\1995167a\126b7c4d\App_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 &地铁轮廓)
- 公共类用户{...}
- MVC 4(.NET 4.5)
- 参考移植类库
- 剃刀视图
- @model用户
由于的Visual Studio 2012 RC添加参考“系统。运行时间“是不可能的。
在视图\ Web.config文件,添加下<system.web>
部分添加以下代码:
<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 Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades
中添加组件的完整列表。
这为什么有效? –
这为我解决了一个类似的问题,使用System.Collections.Immutable – aboy021
根据你在你的项目中做什么,你可能还需要添加同样的行到根'Web.Config' – joshcomley
作为一种解决方法,除了.NET 4.5和Metro风格之外,是否还可以将可移植类库更改为定位Silverlight 5? –