How can I find the platform a .NET assembly has been compiled against programmatically?

吃可爱长大的小学妹 提交于 2019-12-12 19:10:45

问题


Looking at the following JetBrains dotPeek view of some given assemblies, how can I programmatically determine the platform such assemblies have been compiled against?

I have tried the following method which does not work for assemblies compiled in .NET Core.

public static string GetFrameworkVersion(Assembly assembly)
{
    var targetFrameAttribute = assembly.GetCustomAttributes(true)
        .OfType<TargetFrameworkAttribute>().FirstOrDefault();
    if (targetFrameAttribute == null)
    {
        return ".NET 2, 3 or 3.5";
    }

    return targetFrameAttribute.FrameworkDisplayName.Replace(".NET Framework", ".NET");
}

How is dotPeek able to obtain such details?

来源:https://stackoverflow.com/questions/46897911/how-can-i-find-the-platform-a-net-assembly-has-been-compiled-against-programmat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!