有没有办法在不使用mono的情况下在Linux中获取.Net可执行文件的AssemblyVersion?我想要的是一个脚本或命令,让我在Linux机器上获得AssemblyVersion。我试过了:
#strings file.exe | grep AssemblyVersion
but it only the string and not the number. Also checked with:#file file.exe
but only got general information.
有任何想法吗?
尝试匹配跨越整行的版本号:
$ strings file.exe | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
在我的(少数)测试中,二进制文件的AssemblyVersion
始终是最后的结果。
根据Jb Evain的建议,您可以使用Mono Disassembler。
monodis --assembly file.exe | grep Version
同样ikdasm
的distributed with Mono工具比monodis
更强大,不幸的是,许多DLL文件上的消息“Segmentation fault:11”崩溃了。维护者明确建议使用ikdasm
而不是monodis
:https://github.com/mono/mono/issues/8900#issuecomment-428392112
用法示例(使用monodis
目前无法处理的程序集):
ikdasm -assembly System.Runtime.InteropServices.RuntimeInformation.dll | grep Version:
这是一个非常古老的问题,几乎一切都已经改变,但是从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
}