Please note that the solution below is specific to the .NET 4.0 framework, the TargetFrameworkAttribue
is new to 4.0.
I compiled two applications, one against the Client Framework, the other against the full. I opened them both in ildasm.exe and noticed they both had a TargetFrameworkAttribute
applied. You can simply use reflection to see the value:
using System;
using System.Linq;
using System.Runtime.Versioning;
class Program
{
static void Main(string[] args)
{
var a = System.Reflection.Assembly.GetExecutingAssembly();
var att = a.GetCustomAttributes(false).OfType<TargetFrameworkAttribute>().Single();
Console.WriteLine(att.FrameworkDisplayName);
Console.Read();
}
}
Update: Yes indeed, compiling an application against the ".NET Framework 3.5 Client Profile" does not include that attribute (the code can no longer see it and ildasm doesn't feature it). I have no clue, other than the other answer you linked, as to how to determine the target framework in this situation.
To save imposing what I see as pointless limitations on your code base, I would make life easier and simply target the full framework. If the client has permissions on installing the Client Profile, then the same is true for the Full framework - it is just slightly larger (I spotted a source saying it was only 15% larger, thereby negating much of the "smaller client package" benefit, 41MB as opposed to 48MB). Your call.