【问题标题】:How to get the AssemblyVersion of a .Net file in Linux如何在 Linux 中获取 .Net 文件的 AssemblyVersion
【发布时间】:2011-04-26 04:08:05
【问题描述】:

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

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

有什么想法吗?

【问题讨论】:

    标签: .net linux mono assemblyinfo


    【解决方案1】:

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

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

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

    例如在 ubuntu 中

    apt-get install mono-utils
    

    【讨论】:

      【解决方案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
      }
      

      【讨论】:

        【解决方案3】:

        同样是distributed with Monoikdasm 工具比monodis 更强大,不幸的是,它在许多DLL 文件上崩溃并显示“分段错误:11”消息。维护者明确推荐使用ikdasm 而不是monodishttps://github.com/mono/mono/issues/8900#issuecomment-428392112

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

        ikdasm -assembly System.Runtime.InteropServices.RuntimeInformation.dll | grep Version:
        

        【讨论】:

          【解决方案4】:

          按照Jb Evain 的建议,您可以使用Mono Disassembler

          monodis --assembly file.exe | grep Version
          

          【讨论】:

          • 为了与更广泛的程序集样本兼容,请使用 ikdasm -assembly(也与 Mono 一起分发)而不是 monodis --assembly
          【解决方案5】:

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

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

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

          【讨论】:

          • 我测试了它,但我得到的数字都不是 AssemblyVersion。事实上,我在字符串输出的任何地方都没有看到 AssemblyVerson。
          • 在 strings 命令上使用 -el 将字符串解释为 unicode。
          猜你喜欢
          • 2020-04-10
          • 1970-01-01
          • 2011-01-03
          • 1970-01-01
          • 1970-01-01
          • 2015-01-14
          • 2013-01-12
          • 2012-11-21
          • 1970-01-01
          相关资源
          最近更新 更多