How can I determine if a .NET assembly was built for x86 or x64?

后端 未结 15 871
面向向阳花
面向向阳花 2020-11-22 09:08

I\'ve got an arbitrary list of .NET assemblies.

I need to programmatically check if each DLL was built for x86 (as opposed to x64 or Any CPU). Is this possible?

15条回答
  •  既然无缘
    2020-11-22 09:47

    [TestMethod]
    public void EnsureKWLLibrariesAreAll64Bit()
    {
        var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies().Where(x => x.FullName.StartsWith("YourCommonProjectName")).ToArray();
        foreach (var assembly in assemblies)
        {
            var myAssemblyName = AssemblyName.GetAssemblyName(assembly.FullName.Split(',')[0] + ".dll");
            Assert.AreEqual(ProcessorArchitecture.MSIL, myAssemblyName.ProcessorArchitecture);
        }
    }
    

提交回复
热议问题