2

I've created a nuget package in C#.

I want to be able to read the version of the nuget package from within the code in the nuget package (when the code is deployed).

Kind of like this, but instead of the AssemblyVersion I want NugetPackageVersion.

Any clues?

NOTE This is not a duplicate of 'How to get nuget package version programmatically from a nuget feed?', as I want to get the package version from within the code contained within the nuget at runtime, when there is no package manager available.

Sprotty
  • 5,676
  • 3
  • 33
  • 52
  • Framework or core? – Joshua Aug 03 '18 at 14:08
  • 1
    to me it is not a duplicate: Well I think you just want your package version while being in your own assembly, without knowing the path of the package. You have to put the version before compilation into the assembly. Then request it internally from that field. – JackGrinningCat Aug 03 '18 at 17:54
  • 1
    @JackGrinningCat Thats the solution I have at the moment - pushing the package version into a constant property in the code during the build, but it seems clumsy and error prone, I hoped there was a better way. – Sprotty Aug 06 '18 at 08:15
  • Add some example code of what you have in mind, where it will run from and what facilities will have available. To the best of my knowledge, NuGet package metadata isn't present anywhere in the compiled project. – ivan_pozdeev Aug 06 '18 at 16:03
  • 1
    @Sprotty to my knowledge nuget does not change the assemblies, i just rechecked nuget core tools but didn't find anything. If you find it clumpsy and error prone you might want to reconsider using a "package-version" as assembly-version, file-version and informational-version might be sufficient and standard used tools when resolving dependencies – JackGrinningCat Aug 06 '18 at 17:06
  • @JackGrinningCat I think your right. So I think the approach is to embed the package-version in the code, or by conversion keep the assembly-version and the package-version in sync. – Sprotty Aug 16 '18 at 10:18

0 Answers0