4

I would like to create a VS Solution with a project which uses .NET Framework 4.5.2 and another project with 4.6.2 in the same VS Solution.

rene
  • 41,474
  • 78
  • 114
  • 152
John Abel
  • 271
  • 6
  • 20
  • Have you tried to create them? – Markiian Benovskyi Apr 03 '18 at 19:15
  • Yes the references are not matching and say its installed on a different targeted framework. – John Abel Apr 03 '18 at 19:16
  • Is one project referencing something in the other project? – Phil N DeBlanc Apr 03 '18 at 19:18
  • If your project is referencing another as depency, they should be on same framework – Markiian Benovskyi Apr 03 '18 at 19:19
  • Yes the project is referencing the other as a dependency. – John Abel Apr 03 '18 at 19:21
  • 1
    The higher versioned one should be able to reference the lower versioned one, but not the other way around. I'm curious though, why do you want one with 4.5.2 and one with 4.6.2? Why not just use the same framework for both? – Ron Beyer Apr 03 '18 at 19:22
  • Possible Duplicate of [Reference a .net framework 4.5.1 assembly in a 4.0 project](https://stackoverflow.com/questions/23807351/reference-a-net-framework-4-5-1-assembly-in-a-4-0-project) – dsdel Apr 03 '18 at 19:26
  • 1
    It the target version of your EXE project that matters. It must be the higher version and ensures the machine has the required framework version available. Class libraries can be anything equal or less. – Hans Passant Apr 03 '18 at 19:37

3 Answers3

6

Having projects using different versions of .Net in the same solution is fine. When you add references between projects you may have issues. Projects can reference other projects that are at-or-below the version of the referencing project. I.e., a .Net 4.5 project can reference .Net 4.5 projects and lower.

Now if you add a reference to a .Net 4.6.2 project to the .Net 4.5 project, it will not resolve or in other words, the reference simply won't work. Unfortunately, Visual Studio won't stop you (at least at the time of writing) so you need to look for a couple visual cues to let you know something is amiss. One is in the references list under the project in Visual Studio; an exclamation point will show next to your reference like this:

Reference visual cue warning

The other cue will be compile time warnings like this:

Compile time warnings

You'll want to keep an eye out for this since it will most likely cause run time issues if you use that assembly in the referencing project which can be a headache to troubleshoot.

Always Learning
  • 2,623
  • 3
  • 20
  • 39
2

Yes, you can have them in the same solution without impact. Now if you mixed versions referencing each other than it gets into a grey area.

If your code is referencing a library that is the same or less than your target framework than you are usually just fine but you should also check if there are any known issues just to be sure. On the reverse side when your code is ref libraries with higher target framework than you can expect some weird things and unexpected errors to crop up.

Travis Acton
  • 4,292
  • 2
  • 18
  • 30
0

It depends. I just tried it with 4.5.2 and 4.7.1. As long as the references are in place, you can reference an item in the 4.5.2 framework code from the newer version (4.7.1 in my case). However I don't think it will work the other way around.

Phil N DeBlanc
  • 398
  • 1
  • 13