Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get version info of compiled/published dotnet application through bash

I'm developing an ASP.Net Core project, where the .csproj file looks like this:

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>netcoreapp2.0</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>dummyapp</AssemblyName>
        <Version>17.12.1</Version>
    <RuntimeIdentifiers>centos.7-x64;win7-x64</RuntimeIdentifiers>
</PropertyGroup>

When this app is published for Windows, I can get the version info from its properties. Which shows 17.12.1 as mentioned.

Alternatively I can run wmic datafile where name="filepath/app.exe" get Version /value and get the same version using command prompt.


But is there a standard way to get the same in linux distro?

I've looked into:

  • how-to-find-version-of-a-file-or-program

  • Experimented with this answer. Though it is for file-system!

  • Tried myapp --version and /fullpath/myapp --version as mentioned in this post. Also tried solutions with the marked duplicates.

After all the trials, it seems, I need to implement something else in the .csproj file so as to get the version info using bash. Can someone point out what needs to be done, or give a hint about the same.


Main method:

public static void Main(string[] args)
{
    var root = new Root();
    var config = new ConfigurationBuilder()
                     .SetBasePath(Directory.GetCurrentDirectory())
                     .AddJsonFile(SettingsFilename, optional: false,
                                  reloadOnChange: true)
                     .AddEnvironmentVariables()
                     .Build();

    config.Bind(root);

    //some codes

    var host = new WebHostBuilder()
                    .UseKestrel()
                    .UseUrls(root.AppUrl)
                    .UseConfiguration(config)
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseIISIntegration()
                    .ConfigureServices(s =>
                                     s.AddRouting().DetectTokenChange(config))
                    .UseSetting(WebHostDefaults.ApplicationKey, "dummyapp")
                    .Configure(app => app.UseRouter(r => r.MapPost("dumptoqueue", 
                                      async (context) => 
                                      await Task.Run(() => AddtoQueue(context)))))
                    .Build();
     host.Run();
}

App built using the command line:

dotnet publish -c release -r centos.7-x64
like image 458
boop_the_snoot Avatar asked Dec 23 '17 07:12

boop_the_snoot


1 Answers

It might just be easier to use exiftool, if all you need to do via bash is to find the version of a dll file.

$ exiftool Foo.dll | grep -i Version
ExifTool Version Number         : 10.55
Linker Version                  : 48.0
OS Version                      : 4.0
Image Version                   : 0.0
Subsystem Version               : 4.0
File Version Number             : 17.12.1.0
Product Version Number          : 17.12.1.0
File Version                    : 17.12.1.0
Product Version                 : 17.12.1
Assembly Version                : 17.12.1.0

Or even just:

$ exiftool -"ProductVersion" Foo.dll 
Product Version                 : 17.12.1
like image 148
omajid Avatar answered Sep 23 '22 21:09

omajid