Skip to content

Instantly share code, notes, and snippets.

@brianpursley
Created April 16, 2024 17:34
Show Gist options
  • Save brianpursley/b0076f3362c26560d2c290031d23d5fd to your computer and use it in GitHub Desktop.
Save brianpursley/b0076f3362c26560d2c290031d23d5fd to your computer and use it in GitHub Desktop.
Script that prints the version of a .NET assembly
#!/bin/sh
command -v dotnet >/dev/null 2>&1 || { echo >&2 "dotnet is not installed. Please install it and try again."; exit 1; }
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path_to_dll>"
exit 1
fi
temp_dir=$(mktemp -d)
cat > $temp_dir/Program.cs <<EOF
var assembly = System.Reflection.Assembly.LoadFile("${1}");
System.Console.WriteLine(assembly.GetName().Version);
EOF
cat > $temp_dir/temp.csproj <<EOF
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
</Project>
EOF
dotnet run --project $temp_dir/temp.csproj
rm -rf "$temp_dir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment