在Windows 2012 R2上构建.NET应用程序需要做什么?

时间:2014-06-23 09:16:57

标签: .net msbuild

我刚刚设置了一台新的Windows 2012 R2计算机。 MSDN说Windows 2012 R2 has .NET Framework 4.5 included。但是当我构建一个需要.NET 4.5的小应用程序时,它会抛出这些编译错误:

error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
error CS0012: The type 'System.IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
error CS0012: The type 'System.Type' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

如何让这台机器能够编译.NET应用程序?

更新
这些项目是Windows服务和ASP.NET MVC 5网站。

3 个答案:

答案 0 :(得分:4)

我遇到了类似的问题("类型' System.IDisposable'在程序集中定义...")并在我的顶部找到了这个问题搜索结果。 lord_alek1s链接确实包含此问题的修复程序,因此,为了帮助扩展他的答案,我将发布该链接描述的配置更改。

Web.config中的编译标签很可能如下所示:

<compilation debug="true" targetFramework="4.5"/>

将其更改为包含System.Runtime的程序集,如下所示:

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

此错误的原因在另一个SO问题中解释: What does the web.config compilation/assemblies element do?

答案 1 :(得分:0)

我发现了这个问题,因为我在Windows Server 2012 R2上构建Windows窗体应用程序时遇到了同样的错误,因此web.config修改不适用于我。但是(如果其他人来这里遇到与我相同的问题),可以通过安装NET Framework 4.6.1 Developer Pack

来解决这个问题。

答案 2 :(得分:-1)