Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a DLL requires Full .NET 4 or just Client Profile

When using third party assemblies I need a way to detect if they require full .NET 4 or just the .NET 4 Client Profile.

I've seen other ways to detect .NET version referenced Determine .NET Framework version for dll but the ways outlined in that question do not show how to detect Client Profile vs Full. Is it possible?

I'm looking for any solution, it doesn't have to be a code/runtime solution.

like image 599
Evan Avatar asked Nov 03 '22 21:11

Evan


1 Answers

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.

like image 104
Adam Houldsworth Avatar answered Nov 09 '22 11:11

Adam Houldsworth