0

I have a .net 4.8 project with a nuget dependency. This nuget is just a set of pug/js/css files which are copied to a folder on installation. Now I need to print the version of the package in some cases and struggle to do it. Normally I would do it like this:

var version = Assembly.GetExecutingAssembly()
                .GetReferencedAssemblies()
                .FirstOrDefault(x => x.Name == "...")
                ?.Version.ToString();

But in this case, there's no assembly.

Thank you!

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Ulad Melekh
  • 924
  • 3
  • 17
  • 33
  • 1
    You can add a `targets` file [to your nuget](https://github.com/dotnet/project-system/issues/3869), and in the targets file write a custom attribute into the application (see [here](https://stackoverflow.com/a/56940926/15393)). Just change the property from `SolutionFile` to `Version` and ensure the correct version value is written and it should work well (you could even parse out the version number by looking at the `$(MSBuildThisFileDirectory)` path, which will have the nuget package version number as part of it. – RB. Aug 02 '21 at 12:05
  • Can you find the location of your pug/js/css files after installation, and then check those files for a version number? – Joe Sewell Aug 02 '21 at 14:41
  • Yes, I can. That was my initial plan, to add something to the output files, that will have a version (for example version.json file). But I thought maybe it's possible to somehow know in runtime which version of the nuget is installed. – Ulad Melekh Aug 03 '21 at 15:01

0 Answers0