简体   繁体   中英

Target a specific .NET framework

As we know, at Visual Studio for C# project, we could specify what .NET framework we want to target. Here is the app.config file I got when it is target .NET 4.0:

<configuration><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

So there is sku attribute there. Does this mean that my code won't work on machine where .NET 4.0 is NOT installed while .NET 4.5 is installed. I found out that it is confusing from MSDN and I want to get some clarification on this. If so, I would say that is rather bad design. What if I want my code to run on any .NET version of .NET 4.0 and above such as .NET 4.5? I could not distribute different app.config for different env.

When you target a version of .Net you are setting a MINIMUM version required to run your project. You are also restricting yourself to coding with elements of the .Net framework that were available in that version.

At my company we have to target .Net v2.0 on some projects we want to push to all clients because they have old hardware which either isn't or can't run later versions of .Net.

Check this post, It's very well explained:

http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx

Extracted from source:

Developing Safely for both .NET 4 and .NET 4.5

It's been implied on blogs that if you install .NET 4.5 on your machine that you can't safely develop for .NET 4. In Rick's post, he compares two DLLs on a .NET 4 machine and again after the .NET 4.5 in place upgrade. How can you target safely against .NET 4 if you've installed .NET 4.5? You don't have those .NET 4 DLLs anymore, right?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM