Ducain
Ducain

Reputation: 1591

Why does my DLL compile to a .NET version lower than what I chose?

This is a DLL project in C# in VS 2010. My project is set to target .NET 3.5, but when I check my DLL after compile, using Reflector, it says it is .NET 2.0.

My only clue is that I'm referencing a DLL that is .NET 2.0.

Can someone explain this behavior?

Upvotes: 1

Views: 249

Answers (2)

Hans Passant
Hans Passant

Reputation: 941724

It is not the way it works. An assembly targets a CLR version. Version 2.0.50727 for any project that targets .NET 2.0 through 3.5 SP1. Which are not side-by-side versions, 3.0, 3.5 and 3.5SP1 just added extra assemblies. They still use the same CLR and the same base class assemblies.

Until .NET 4.0, an entirely new version of .NET with a new version of the CLR. Version 4.0.30319. And it is a side-by-side version, you can have both .NET 4 and .NET 3.5SP1 installed on the machine.

.NET 4.5 is again an update which replaces 4.0 and uses the same CLR version.

The use of setting the .NET Framework target version in your project is to help catch the IDE you accidentally using assemblies that are only available in a later release. You could still build your project but of course it isn't going to run on the user's machine. You want to know about that.

Upvotes: 3

Nick Zimmerman
Nick Zimmerman

Reputation: 1531

.NET 3.5 is a series of extensions that build on the .NET 2.0 framework, but the underlying runtime is still the same as in .NET 2.0. So the DLL shows as .NET 2.0 because it is compiled for the .NET 2.0 runtime.

Upvotes: 5

Related Questions