Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Linux中获取.Net文件的AssemblyVersion_.net_Linux_Mono_Assemblyinfo - Fatal编程技术网

如何在Linux中获取.Net文件的AssemblyVersion

如何在Linux中获取.Net文件的AssemblyVersion,.net,linux,mono,assemblyinfo,.net,Linux,Mono,Assemblyinfo,有没有办法在Linux中获得.Net可执行文件的汇编版本而不使用mono?我正在尝试的是一个脚本或命令,可以让我在Linux机器上获得AssemblyVersion。我试过了:但它只是字符串而不是数字。还检查了:但只获得了一般信息 #strings file.exe | grep AssemblyVersion #file file.exe 有什么想法吗?尝试匹配跨一整行的版本号: $ strings file.exe | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9

有没有办法在Linux中获得.Net可执行文件的汇编版本而不使用mono?我正在尝试的是一个脚本或命令,可以让我在Linux机器上获得AssemblyVersion。我试过了:但它只是字符串而不是数字。还检查了:但只获得了一般信息

#strings file.exe | grep AssemblyVersion
#file file.exe

有什么想法吗?

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

$ strings file.exe | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
在我的(少数)测试中,二进制文件的
AssemblyVersion
始终是最后的结果。

如您所建议的,可以使用


ikdasm
工具也比
monodis
更健壮,不幸的是,该工具在许多DLL文件上出现消息“Segmentation fault:11”时崩溃。维护人员明确建议使用
ikdasm
而不是
monodis

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

这是一个非常古老的问题,几乎所有的事情都发生了变化,但从dotnet 2.1开始(因此您可以
dotnet工具安装
),您可以安装
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
}

我测试了它,但没有一个数字是我得到的汇编版本。事实上,我在字符串输出的任何地方都看不到AssemblyVerson。请在strings命令上使用
-el
将字符串解释为unicode。为了与更广泛的程序集示例兼容,请使用
ikdasm-assembly
(也使用Mono分发)而不是
monodis--assembly
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
}