Get Assembly Version from DOS prompt
Recently I wanted to get the build version number from a compiled assembly. I wanted to package some files together into an .msi installer and then copy the .msi file into a folder with the version number of the application.
It turns out theres not a real easy way to do this from a shell script, so I had to write a small console app that would take in an assembly file path and write out the version number (download it here). Next, I wanted to take the output from this app and store it in a variable in my batch file, something like this:
assver.exe myAssemblyPath > myVariableName
Now, I realize that the ‘>’ redirects the output to a file, but I wish there was a way to redirect the output to a variable instead. I had to redirect the output to a text file, then read the contents of that file into a variable, ugh. Heres the full code for that:
Tools\assver “myAssemblyPath” > version.txt
for /F %%a in (’type version.txt’) do set ver=%%a
del version.txt
So I write the version number to a file, read the file into my variable, then delete the file, quick and dirty.
As an aside, I’m using Wix to create the .msi and MSBuild to build the code. I like using Wix better than having a setup project in VS, it has more options and it doesn’t clutter up VS with an extra project. My installer is very basic at this point, but Wix is clearly a very powerful install tool, with many options, I’m just getting up to speed. I’ve found this Wix tutorial that has a TON of useful information.