Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does compiling with a specific .NET version provides any benefits?

My .NET assembly is used in various projects that run on .NET 2.0, 3.5, 4.0, 4.5. 4.5.1, 4.5.2, 4.6.1, 4.6.2.

My .NET assembly does not use any features except provided with .NET 2.0.

Which .NET versions should I compile my .NET assembly with? It looks like only 2 versions make sense: .NET 2.0 and .NET 4.0. Dose compiling with any other .NET versions provide any benefits?

like image 413
IT Hit WebDAV Avatar asked Sep 17 '25 23:09

IT Hit WebDAV


1 Answers

Its probably a good idea to distinguish between versions of the .NET Framework versus versions of the Common Language Runtime

Common Language Runtime

The Common Language Runtime (CLR) is the component that is responsible for running the platform independent IL code on your target machine. You'll need to compile your app against all of the CLR versions that you need to support.

There are the following CLR versions at the time of writing:

  • 4.0
  • 2.0
  • 1.1
  • 1.0

.NET Framework

The .NET framework version is basically the version of the system assemblies that make up .NET. Each version of .NET is designed to work against a specific version of the CLR, but more than one .NET framework version uses the same version of the CLR. For example CLR 4.0 is used by .NET 4.0, 4.5 and 4.6.

You can see the versions of .NET Framework, and which CLR versions they use here: https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx

You shouldn't need to rebuild your library against newer versions of the framework if your already building against an older .NET version that targets the same CLR version. Any system assemblies referenced should have been upgraded in one of the following ways to ensure backward compatibility:

  • A 'safe' in place upgrade that behaves in the same way as the previous version unless code specifically opt in to new behavior (e.g. by calling a new method, instantiating a new class etc).

  • Adding a new assembly. Because .NET framework uses version numbers as part of the name binding you'll still get the version you compiled against, even if other libraries in the AppDomain are referencing the newer version with the same name.

Note that the opposite doesn't work. You can never assume your class library will work against a older version of .NET than the version compiled against, even if the CLR version is the same.

like image 131
Andrew Skirrow Avatar answered Sep 20 '25 13:09

Andrew Skirrow