0 votes
by (130 points)

Hello,

I want to get the target .NET Compact Framework for Rebex.common.dll of CE.

In C# coding when i check the TargetFramework attribute for the assembly it always return 4.0 but i expect it to return the .NET Compact Framework 3.5. Is there any way to get this information by using c# coding?

Although when check the properties of dll by right click on it. The description field tells that its .NET Compact Framework 3.5

Thanks

1 Answer

0 votes
by (134k points)

The most simple way to determine the .NET CF version targeted by a Rebex DLL is to use .NET's FileVersionInfo to retrieve the "description", which includes the platform name:

public static Version GetCompactFrameworkPlatform(string assemblyPath)
{
    var info = FileVersionInfo.GetVersionInfo(assemblyPath);
    string description = info.FileDescription;
    if (description.EndsWith(" for .NET Compact Framework 3.9", StringComparison.Ordinal) ||
        description.EndsWith(" for .NET CF 3.9", StringComparison.Ordinal))
    {
        return new Version(3, 9);
    }

    if (description.EndsWith(" for .NET Compact Framework 3.5", StringComparison.Ordinal) ||
        description.EndsWith(" for .NET CF 3.5", StringComparison.Ordinal))
    {
        return new Version(3, 5);
    }

    if (description.EndsWith(" for .NET Compact Framework 2.0", StringComparison.Ordinal) ||
        description.EndsWith(" for .NET CF 2.0", StringComparison.Ordinal))
    {
        return new Version(2, 0);
    }

    return null;
}

This code is suitable for Rebex DLLs published in 2017 or later.

...