VB.Net - 检查文件是否为.net二进制文件

nex*_*xno 2 c# vb.net native managed file

如何查看文件,如何查看VB.Net

C:\文件\将Test.exe

是.net二进制文件还是原生二进制文件?

Lok*_*oki 7

MSDN 如何:确定文件是否为程序集(C#和Visual Basic):

如何以编程方式确定文件是否为程序集

  1. 调用GetAssemblyName方法,传递正在测试的文件的完整文件路径和名称.
  2. 如果BadImageFormatException抛出异常,则该文件不是程序集.

它甚至有一个VB.NET示例:

Try 
    Dim testAssembly As Reflection.AssemblyName =
                            Reflection.AssemblyName.GetAssemblyName("C:\Windows\Microsoft.NET\Framework\v3.5\System.Net.dll")
    Console.WriteLine("Yes, the file is an Assembly.")
Catch ex As System.IO.FileNotFoundException
    Console.WriteLine("The file cannot be found.")
Catch ex As System.BadImageFormatException
    Console.WriteLine("The file is not an Assembly.")
Catch ex As System.IO.FileLoadException
    Console.WriteLine("The Assembly has already been loaded.")
End Try
Run Code Online (Sandbox Code Playgroud)

这并不理想,因为它使用控制流的异常.

我也不确定它在角落情况下的表现如文件是程序集,但不支持当前的CPU体系结构,或者它是否针对框架的不受支持的变体.