Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. This build server is also used to build and deploy older projects, as well, some of which target .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:

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. 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.

To sum up:

  • Project targets 4.0
  • Build server has 4.5 installed
  • The server on which the project is then deployed has only .NET 4.0
  • Project fails at runtime with error 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?

like image 928
David Mills Avatar asked Feb 12 '13 21:02

David Mills


People also ask

Can I upgrade my. net Framework?

If you created your app using an earlier version of . NET Framework, you can generally upgrade it to . NET Framework 4.5 and its point releases (4.5. 1 and 4.5.

What is the .NET framework for Visual Studio 2019?

NET version 5 (Visual Studio 16.8 or later) . NET Framework versions 4.8, 4.7.

Where does .NET framework install?

NET in the File System. You can check your installed versions of . NET by navigating to Microsoft.NET\Framework under your Windows folders. The complete path is usually 'C:\Windows\Microsoft.NET\Framework.


1 Answers

This occurs because 4.5 is an in-place upgrade to 4.0. When the build server compiles, by default, it will find the 4.5 assemblies even if you're targeting .NET 4.

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.

For details, see Marc Gravell's blog post on the subject.

like image 51
Reed Copsey Avatar answered Oct 18 '22 12:10

Reed Copsey