Reputation: 3294
Is there any way to obtain the AssemblyVersion of a .Net executable in Linux without using mono? What I am trying to have is a script or command that will let me obtain the AssemblyVersion on Linux boxes. I tried:
#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.
Any ideas?
Upvotes: 39
Views: 23866
Reputation: 33592
Another option is to use exiftool
, as in:
$ exiftool -AssemblyVersion -ProductVersion ./System.Private.CoreLib.dll
Assembly Version : 7.0.0.0
Product Version : 7.0.4+0a396acafe9a7d46bce11f4338dbb3dd0d99b1b4
Upvotes: 15
Reputation: 3746
to return just the vesion using monodis, use this code
monodis --assembly LDAPService.dll | grep Version | awk -F ' ' '{print $2}'
Installation packages: https://command-not-found.com/monodis
For example in ubuntu
apt-get install mono-utils
Upvotes: 3
Reputation: 14969
This is a really old question and just about everything has changed, but as of dotnet 2.1 (so you can dotnet tool install
) you can install dotnet-ildasm
:
dotnet tool install --tool-path . dotnet-ildasm
Then you can use this function:
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
}
Upvotes: 3
Reputation: 780
The ikdasm
tool that is also distributed with Mono is more robust than monodis
, which unfortunately crashes with the message "Segmentation fault: 11" on many DLL files. The maintainers explicitly recommend the use of ikdasm
rather than monodis
: https://github.com/mono/mono/issues/8900#issuecomment-428392112
Usage example (with an assembly that monodis
currently cannot handle):
ikdasm -assembly System.Runtime.InteropServices.RuntimeInformation.dll | grep Version:
Upvotes: 5
Reputation: 2773
As recommended by Jb Evain you can use the Mono Disassembler.
monodis --assembly file.exe | grep Version
Upvotes: 15
Reputation: 263107
Try to match version numbers that span a whole line:
$ strings file.exe | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
In my (few) tests, the AssemblyVersion
of the binary was always the last result.
Upvotes: 34