FAKE icon indicating copy to clipboard operation
FAKE copied to clipboard

Getting assembly version

Open Ravadre opened this issue 12 years ago • 6 comments

Hi, in my build scripts I tend to like to read assembly's version and use it later for example when creating nuget packages. I looked at Fake's Api but couldn't find any method which would do this, I tend to use one-liner like this for myself:

let getVersion file = System.Reflection.Assembly.ReflectionOnlyLoadFrom(file).GetName().Version.ToString()

Is there a ready-to use method? If no, would it be a good idea to add one?

I am aware that this sample is simplistic of course, as it doesn't release resources, so probably calling it in different AppDomain and marshalling the result back would be a good idea.

Ravadre avatar May 08 '14 20:05 Ravadre

Usually most FAKE projects define AssemblyVersions in a Release Notes file like https://github.com/fsharp/FAKE/blob/develop/RELEASE_NOTES.md or retrieve them from a CI server. So usually we already use FAKE to set the AssemblyVersions (see http://fsharp.github.io/FAKE/assemblyinfo.html) and use the same version for the nuget packages.

That said: Yes I think this might be useful. Please describe your use case and send a pull request.

forki avatar May 09 '14 07:05 forki

I'm using global assembly info / solution info approach for some time, even before I was using Fake. Few ideas why setting version through AssemblyVersion might not be enough for all cases:

  • It's language dependent, so for example it doesn't work for C++/Cli
  • I like to use "*" placeholder in version sometimes, so that some random version will be generated, so I can only get version of assembly once it's compiled.

I will send a pull request this weekend.

Ravadre avatar May 09 '14 12:05 Ravadre

You can retrieve the assembly version without using ReflectionOnlyLoadFrom.

let getVersion file = System.Reflection.AssemblyName.GetAssemblyName(file).Version.ToString()

I'm doing so successfully in FeatureSwitcher build

mexx avatar May 09 '14 12:05 mexx

@mexx: Thanks, I didn't know that and it's a much better what I use, especially considering:

This will only work if the file contains an assembly manifest. This method causes the file to be opened and closed, but the assembly is not added to this domain.

Which solves file lock and loading to AppDomain at once.

Ravadre avatar May 09 '14 12:05 Ravadre

ok if you both use it, then we should find a way to put it in FakeLib.

forki avatar May 09 '14 12:05 forki

Resolved by #423

Ravadre avatar May 14 '14 17:05 Ravadre