Guaranteed way to find the filepath of the ildasm.exe and ilasm.exe files regardless of .NET version/environment?

前端 未结 2 1538
生来不讨喜
生来不讨喜 2021-02-14 10:12

Is there a way to programmatically get the FileInfo/Path of the ildasm.exe/ilasm.exe executables? I\'m attempting to decompile and recompile a dll/exe file appropriately after m

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 10:36

    One option would be to reference Microsoft.Build.Utilities.Core and use:

    var ildasm = Microsoft.Build.Utilities.ToolLocationHelper.GetPathToDotNetFrameworkSdkFile("ildasm.exe", TargetDotNetFrameworkVersion.VersionLatest);
    var ilasm = Microsoft.Build.Utilities.ToolLocationHelper.GetPathToDotNetFrameworkFile("ilasm.exe", TargetDotNetFrameworkVersion.VersionLatest);
    

    Right now on my machine this returns:

    ildasm = C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\ildasm.exe

    ilasm = C:\Windows\Microsoft.NET\Framework\v4.0.30319\ilasm.exe

提交回复
热议问题