【问题标题】:What do I need to do to build .NET application on Windows 2012 R2?在 Windows 2012 R2 上构建 .NET 应用程序需要做什么?
【发布时间】:2014-06-23 09:16:56
【问题描述】:

我刚刚设置了一台新的 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 app?

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

【问题讨论】:

  • 很明显,您需要告诉我们很多更多关于您创建的项目的信息。
  • @HansPassant 我编辑了我的问题以包含项目的类型。它们是 Windows 服务和 ASP.NET MVC 5 网站。

标签: .net msbuild


【解决方案1】:

我刚刚遇到了一个类似的问题(“'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?

【讨论】:

    【解决方案2】:

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

    解决了这个问题

    【讨论】:

      【解决方案3】:

      【讨论】:

      • 尝试总结文章中的信息,因为如果链接断开或失效,您的回答对于将来访问此页面的人来说毫无用处。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 2016-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      相关资源
      最近更新 更多