Answered by:
Use different target framework in projects.

Question
-
My solution has 6 projects in VS 2012. One of them targets .net 4.5 as it use async/await, the rest of them use .net 4 as they are the old code.
I got something like
*The primary reference "xxxx.Library, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0"
Any idea?Wednesday, April 8, 2015 7:23 PM
Answers
-
The error message explains the problem - a .NET 4 app can't reference a .NET 4.5 dll. Change your app to .NET 4.5 as well, or change the dll back to .NET 4.
Apparently if you have only .NET Frameworks 4.0 installed, you can add as a reference a .NET assembly that targets 4.5 to a project that targets .NET 4.0. This will compile and run with no errors.
As soon as you install .NET Frameworks 4.5, compile will fail. The solution is to target your project for .NET Framework 4.5 or get a version of the referenced assembly that targets .NET 4.0.
.NET 4.5 is a drop in replacement for 4.0. 4.0 doesn't know anything about 4.5, and I assume it is just looking at the first digit of the version number which for 4.0 or 4.5 is the same, so it is allowed to compile. As soon as you install 4.5, your 4.0 projects are compiled using the 4.5 Frameworks and it now knows about 4.5 and complains.
Rachit
Please mark as answer or vote as helpful if my reply does
- Edited by Rachit Sikroria Wednesday, April 8, 2015 7:32 PM
- Proposed as answer by Rachit Sikroria Thursday, April 9, 2015 11:32 AM
- Marked as answer by HZ.USA Thursday, April 9, 2015 12:32 PM
Wednesday, April 8, 2015 7:31 PM -
Let me add more. Say the solution has six projects: A,B,C,D,E and F.
A: It is new project(class library) which targets .net 4.5 because it uses async/await.
B, C,D,E,F: They are old projects, which use asp.net mvc 2. They are targeting .net 4 and in production already. They won't be changed as too much work. Project B will reference A.
Do you mean rewrite project A? The question is .NET 4 doesn't support async/await. Also it need a lot work.
The .NET Framework 4 is backward-compatible with applications that were built with the .NET Framework versions 1.1, 2.0, 3.0, and 3.5. In other words, applications and components built with previous versions of the .NET Framework will work on the .NET Framework 4. But in your scenario, Project A (class library) which targets .NET Framework 4.5. So fail to built.
Please also build Project A to .NET Framework 4 Or do like Rachit's suggestions . It will be OK.
Best regards&&Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Kristin Xie Thursday, April 9, 2015 8:28 AM
- Proposed as answer by Rachit Sikroria Thursday, April 9, 2015 11:32 AM
- Marked as answer by Kristin Xie Sunday, April 19, 2015 2:36 AM
Thursday, April 9, 2015 8:28 AM
All replies
-
The error message explains the problem - a .NET 4 app can't reference a .NET 4.5 dll. Change your app to .NET 4.5 as well, or change the dll back to .NET 4.
Apparently if you have only .NET Frameworks 4.0 installed, you can add as a reference a .NET assembly that targets 4.5 to a project that targets .NET 4.0. This will compile and run with no errors.
As soon as you install .NET Frameworks 4.5, compile will fail. The solution is to target your project for .NET Framework 4.5 or get a version of the referenced assembly that targets .NET 4.0.
.NET 4.5 is a drop in replacement for 4.0. 4.0 doesn't know anything about 4.5, and I assume it is just looking at the first digit of the version number which for 4.0 or 4.5 is the same, so it is allowed to compile. As soon as you install 4.5, your 4.0 projects are compiled using the 4.5 Frameworks and it now knows about 4.5 and complains.
Rachit
Please mark as answer or vote as helpful if my reply does
- Edited by Rachit Sikroria Wednesday, April 8, 2015 7:32 PM
- Proposed as answer by Rachit Sikroria Thursday, April 9, 2015 11:32 AM
- Marked as answer by HZ.USA Thursday, April 9, 2015 12:32 PM
Wednesday, April 8, 2015 7:31 PM -
Let me add more. Say the solution has six projects: A,B,C,D,E and F.
A: It is new project(class library) which targets .net 4.5 because it uses async/await.
B, C,D,E,F: They are old projects, which use asp.net mvc 2. They are targeting .net 4 and in production already. They won't be changed as too much work. Project B will reference A.
Do you mean rewrite project A? The question is .NET 4 doesn't support async/await. Also it need a lot work.
Wednesday, April 8, 2015 8:01 PM -
Let me add more. Say the solution has six projects: A,B,C,D,E and F.
A: It is new project(class library) which targets .net 4.5 because it uses async/await.
B, C,D,E,F: They are old projects, which use asp.net mvc 2. They are targeting .net 4 and in production already. They won't be changed as too much work. Project B will reference A.
Do you mean rewrite project A? The question is .NET 4 doesn't support async/await. Also it need a lot work.
The .NET Framework 4 is backward-compatible with applications that were built with the .NET Framework versions 1.1, 2.0, 3.0, and 3.5. In other words, applications and components built with previous versions of the .NET Framework will work on the .NET Framework 4. But in your scenario, Project A (class library) which targets .NET Framework 4.5. So fail to built.
Please also build Project A to .NET Framework 4 Or do like Rachit's suggestions . It will be OK.
Best regards&&Kristin
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Edited by Kristin Xie Thursday, April 9, 2015 8:28 AM
- Proposed as answer by Rachit Sikroria Thursday, April 9, 2015 11:32 AM
- Marked as answer by Kristin Xie Sunday, April 19, 2015 2:36 AM
Thursday, April 9, 2015 8:28 AM