Fun with Moniker- naming assembly versions
I liked the way docker generates names for every container instance – it was a funny way to differentiate them. I was thinking – what about nuget packages – or any other release ?
I have discovered Moniker – https://github.com/alexmg/Moniker . Can be used as in docker – to generate different names at various runs. However, what I wanted is to make every release to have a funny name.
I have put in .NET Core local tools ( see https://youtu.be/iHLRBxi4S7c and the blog post http://msprogrammer.serviciipeweb.ro/2020/06/08/net-core-local-tools/ ) and I have used from powershell ( see https://github.com/ignatandrei/NETCoreBlockly/ for the usage)
First, I have created a variable
if($result -eq 0){
$moniker = “$(dotnet moniker -s moby)-$dateToPrint”
}
else{
$moniker = “$(dotnet moniker -s moniker)-$dateToPrint”
}
then used this variable in the release notes
$releaseNotes += (“;BuildNumber $env:BUILD_BUILDNUMBER with name “+ $moniker)
and in assembly title
dotnet-property “**/*.csproj” AssemblyTitle:”NetCoreBlockly $moniker”
Then, in C# , I write in the console:
static string nameBlockly()
{
var ass = Assembly.GetExecutingAssembly();
var assName = ass.GetName();
var nameBlockly = assName.Name;
try
{
var title = ass.GetCustomAttribute<AssemblyTitleAttribute>();
nameBlockly = title?.Title ?? nameBlockly;
}
catch
{
//do nothing
}
return $”{nameBlockly} version:{assName.Version.ToString()}”;
}
If you want to see in action , you can:
- Look at the nuget release notes at https://www.nuget.org/packages/NetCore2Blockly/ ( see BuildNumber … with name
- See the change log https://github.com/ignatandrei/NETCoreBlockly/blob/master/changelog.md – every release has the name
- Install NetCoreBlockly and see the name
Leave a Reply