简体   繁体   中英

How to target .net framework 4.0 from a SilverLight 4 Application Project?

Issue: When creating a new SilverLight Application Project from Visual Studio 2010, the SilverLight application project's reference pointing to .Net Framework 2.0 assemblies. But I need to use some features only available since .Net Framework 4.0.

Had done a few Google searches but reached no conclusion.

Is there a way to update the targeted .Net Framework version for SilverLight application project in Vs2010?

Silverlight and the full-on .NET Framework are separate things, that just happen to share an awful lot in common. The version numbers of these gets even more confusing, but here goes...

Silverlight 1 didn't have managed code so I'll skip that.

Silverlight 2, 3, and 4 all have version numbers like "2.0.5.0" for the various assemblies (System.dll, System.Core.dll, etc...) - the "5" is meant to look like an "S" for Silverlight, and also makes it unique vs. the "2.0.0.0" that the full .NET Framework uses. This is important because Silverlight is a subset of the .NET Framework, so if an application loads a DLL they may think that 2.0.0.0 means "I can use API Foo" but that API might be subsetted out of Silverlight - so at least "2.0.5.0" implies "this is not exactly the same".

Silverlight uses a CLR called the "CoreCLR" whereas the full .NET Framework uses simply "the CLR" - CoreCLR is a subset of the full CLR and doesn't have all of its functionality (but does run on Mac, so that's a plus). Silverlight 2 and 3 use CoreCLR 2, which is fairly close to full CLR 2 (used by .NET Framework 2-3.5). Silverlight 4 uses CoreCLR 4, which is fairly close to full CLR 4 (used by .NET Framework 4).

To throw another wrench in these works, Silverlight for Windows Phone 7 uses the .NET Compact Framework, which has yet a different CLR (the NETCF CLR).

Last thing to note is that recently Microsoft has started the "Portable Library Project" (see here : http://blogs.msdn.com/b/bclteam/archive/2011/01/19/announcing-portable-library-tools-ctp-justin-van-patten.aspx ) which aims to make it easier to build class libraries that can run on all the various ".NET-like" things out there (full .NET, Silverlight, Windows Phone, XNA on XBox 360, perhaps others like Mono) without the developer having to worry about the morass of stuff I just mentioned above.

Hopefully that makes things clearer, but it is rather confusing.

So to get back to your question - you can't "target .NET 4 from Silverlight" but if there's a feature of the CLR or the Base Class Library from .NET 4, it may be in Silverlight 4 as well. If you can list specific features you're seeking, I can tell you if they're in Silverlight 4.

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