Using .NET 3.5 features on .NET 2.0.... and it's working?
My .NET app runs as a plugin to a C++ MFC desktop app which provides a .NET SDK. The main app is in charge of loading .NET before it loads any plugins. I'm compiling my project against .NET 3.5, and the following test code works just fine:
MainApp.WriteLine("MyPlugin running on .NET {0}.{1}", _
开发者_开发百科 System.Environment.Version.Major, _
System.Environment.Version.Minor)
Dim data As Int32() = New Int32() {1, 1, 1, 1, 4, 4, 4, 4, 12, 12, 12, 12}
For Each distinctValue As Int32 In data.Distinct()
MainApp.Write(distinctValue.ToString() & ", ")
Next
This is Linq code which should only run on .NET 3.5 right? However when it prints the version message it claims that "MyPlugin running on .NET 2.0"
Why/How is this working and can I rely on it to always work, provided .NET 3.5 has been installed?
At a guess, it is reporting the core version of .NET, which is 2.0. This was not updated unti lversion 4.0, because the core code is the same.
Some features in .net 3.5 are only syntactic sugar, and the compiler compiles them to MSIL that can be executed by the 2.0 runtime.
So you only need VS 2008 and .net 3.5 on your development machine, but the machines where the compiled app will run on need only the 2.0 runtime.
See this question here at SO:
What features of .NET 3.5 can be used in a .NET 2.0 application?
精彩评论