28

有没有办法在不使用单声道的情况下在 Linux 中获取 .Net 可执行文件的 AssemblyVersion?我想要的是一个脚本或命令,它可以让我在 Linux 机器上获得 AssemblyVersion。我试过了:

#strings file.exe | grep AssemblyVersion
但它只是字符串而不是数字。还检查了:
#file file.exe
但只得到一般信息。

有任何想法吗?

4

5 回答 5

20

尝试匹配跨越整行的版本号:

$ strings file.exe | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'

在我的(少数)测试中,AssemblyVersion二进制文件始终是最后一个结果。

于 2010-10-15T22:03:27.320 回答
14

根据Jb Evain的建议,您可以使用Mono Disassembler

monodis --assembly file.exe | grep Version
于 2013-08-29T19:04:47.210 回答
4

也与 Mono 一起分发ikdasm工具比 更强大,不幸的是,它在许多 DLL 文件上崩溃并显示消息“分段错误:11”。维护者明确建议使用而不是:https ://github.com/mono/mono/issues/8900#issuecomment-428392112monodisikdasmmonodis

使用示例(使用monodis当前无法处理的程序集):

ikdasm -assembly System.Runtime.InteropServices.RuntimeInformation.dll | grep Version:
于 2018-10-19T08:20:20.733 回答
2

这是一个非常古老的问题,几乎所有事情都发生了变化,但是从 dotnet 2.1(所以你可以dotnet tool install)开始,你可以安装dotnet-ildasm

dotnet tool install --tool-path . dotnet-ildasm

然后你可以使用这个功能:

function dll_version {
  local dll="$1"
  local version_line
  local version

  version_line="$(./dotnet-ildasm "$dll" | grep AssemblyFileVersionAttribute)"
  # Uses SerString format:
  #   01 00 is Prolog
  #   SZARRAY for NumElem
  #   version chars for Elem
  #   00 00 for NamedArgs
  # See:
  #   https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf#%5B%7B%22num%22%3A2917%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C87%2C321%2C0%5D
  [[ $version_line =~ \(\ 01\ 00\ [0123456789aAbBcCdDeEfF][0123456789aAbBcCdDeEfF]\ (.*)\ 00\ 00\ \)$ ]]
  dotcount=0
  for i in ${BASH_REMATCH[1]}; do
    if [[ $i =~ ^2[eE]$ ]]; then
      (( dotcount++ ))
    fi
    if (( dotcount == 3 )); then
      break
    fi
    echo -n -e "\u$i"
  done
}
于 2019-02-07T16:14:16.067 回答
0

要使用 monodis 仅返回 vesion,请使用此代码

monodis --assembly LDAPService.dll | grep Version | awk -F ' ' '{print $2}'

安装包:https ://command-not-found.com/monodis

例如在 ubuntu 中

apt-get install mono-utils
于 2021-09-16T17:01:34.767 回答