4

For complicated reasons involving historical projects, we have a core project that is shared across many products. The issue is that we can't migrate the project to 4.5 because we have some products that must work on Windows XP. Is there any workaround so that I can reference a .NET 4.5 dll from that .NET 4.0 project?

I realize that we could branch the project, one for each .NET version, but that introduces a lot of maintenance overhead....

Any help would be great!

EDIT - To be clear, we would like it to reference a .NET 4.5 dll, but any of our products that run on Windows XP wouldn't execute anything from it, only our newer products would utilize its features.

Luthian
  • 69
  • 1
  • 4
  • 4
    If you needed to load the 4.5 DLL on the XP machine, what do you think would happen? – Scott Chamberlain Jun 21 '13 at 19:10
  • Here's the same question 0.5 versions ago http://stackoverflow.com/questions/3791078/can-you-use-a-net-4-0-dll-in-a-3-5-project and the (accepted) answer is no. I think that applies in a 4.0 => 4.5 scenario too. – Marcello Romani Jun 21 '13 at 19:15
  • Why do you want to reference a DLL that you're not going to use? That doesn't make much sense to me. – svick Jun 21 '13 at 19:17
  • We're going to use it, just not in every single one of our products (specifically our products that need to run on XP) – Luthian Jun 21 '13 at 19:20
  • Why are you including DLL's as references in your products that are not necessary? – Scott Chamberlain Jun 21 '13 at 19:29
  • They are necessary from some projects, but not all. We're trying to find a way to accommodate both without having to maintain separate core projects for various versions of .NET, although it appears we may have to do so. We're not sure it's worth maintaining multiple versions because we only want to use a few .NET 4.5 features. That's why I was curious if there was an acceptable workaround for this type of situation, which it doesn't look like there is. – Luthian Jun 21 '13 at 19:40
  • You are asking this question in a very unproductive way. Mention the *specific* class do you need that's available only in 4.5 – Hans Passant Jun 21 '13 at 20:02
  • @HansPassant it was meant to be vague. I'm just researching what our options are, so I don't have specifics. There are some Attribute additions, LINQ changes, and parallelism advantages that I would love to incorporate where we could. – Luthian Jun 21 '13 at 20:11

1 Answers1

8

The issue is that we can't migrate the project to 4.5 because we have some products that must work on Windows XP.

If these products use the "core project", you'll need to leave it targeting .NET 4.0 or earlier. There is no way to use a .NET 4.5 assembly from any project on Windows XP.

If you need .NET 4.5 features, you'll need to either upgrade those projects, or maintain two versions.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • It seems that you can use a newer .NET version dll into a previous version project, but it's too much hassle for it to be worth the trouble; for anyone interested on this, I leave the link here: http://blog.jdhardy.ca/2012/09/changing-net-assembly-platforms-with.html – Rafael Jun 24 '13 at 17:42
  • @Rafael That article actually uses assembly rewriting, so it's making a *new assembly* from the old one. Very nasty, but still would require two versions... – Reed Copsey Jun 24 '13 at 17:44