简体   繁体   English

可以成功安装.NET 4.5的构建服务器将面向4.0的项目部署到仅安装了.NET 4.0的服务器吗?

[英]Can a build server with .NET 4.5 installed successfully deploy a project targeting 4.0 to a server with only .NET 4.0 installed?

We've recently installed .NET 4.5 onto our continuous integration build server so that it can support new projects that utilize features of .NET 4.5. 我们最近在我们的持续集成构建服务器上安装了.NET 4.5,以便它可以支持利用.NET 4.5功能的新项目。 This build server is also used to build and deploy older projects, as well, some of which target .NET 4.0. 此构建服务器还用于构建和部署旧项目,其中一些目标是.NET 4.0。

Projects that target .NET 4.0 being built on this server, then deployed to a target server that has only .NET 4.0 installed are now failing with the following error: 针对在此服务器上构建的.NET 4.0,然后部署到仅安装了.NET 4.0的目标服务器的项目现在失败,并出现以下错误:

Method not found: 'Int32 System.Environment.get_CurrentManagedThreadId()'.

Environment.CurrentManagedThreadId is a new property of .NET Framework 4.5, so it makes sense that a server running 4.0 can't find it. Environment.CurrentManagedThreadId是.NET Framework 4.5的新属性,因此运行4.0的服务器无法找到它。 However, we are targeting .NET 4.0 at build time, so in theory we shouldn't need to have 4.5 installed on the production server. 然而,我们构建时针对.NET 4.0,因此从理论上讲,我们不应该需要安装在生产服务器上4.5。

To sum up: 总结一下:

  • Project targets 4.0 项目目标4.0
  • Build server has 4.5 installed Build server已安装4.5
  • The server on which the project is then deployed has only .NET 4.0 然后部署项目的服务器只有.NET 4.0
  • Project fails at runtime with error Method not found: 'Int32 System.Environment.get_CurrentManagedThreadId()'. 项目在运行时失败,错误Method not found: 'Int32 System.Environment.get_CurrentManagedThreadId()'.

What gives? 是什么赋予了? Is it possible to successfully run .NET 4.0 dlls on a server with only .NET 4.0 installed when the dlls are built by a server with .NET 4.5? 在使用.NET 4.5的服务器构建dll时,是否可以在仅安装了.NET 4.0的服务器上成功运行.NET 4.0 dll?

This occurs because 4.5 is an in-place upgrade to 4.0. 发生这种情况是因为4.5是4.0的就地升级。 When the build server compiles, by default, it will find the 4.5 assemblies even if you're targeting .NET 4. 当构建服务器编译时,默认情况下,即使您的目标是.NET 4,它也会找到4.5程序集。

You can correct this, but you need to add the 4.0 reference assemblies to your build server (so the compiler finds them), and not just rely on the .NET 4.5 versions. 您可以更正此问题,但是您需要将4.0引用程序集添加到构建服务器(以便编译器找到它们),而不仅仅依赖于.NET 4.5版本。

For details, see Marc Gravell's blog post on the subject . 有关详细信息,请参阅Marc Gravell关于此主题的博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM