Documentation of .fsproj
files
I believe the format is the same as csproj
as far as MSBuild is concerned
You can find the official documentation about the csproj files here:
https://learn.microsoft.com/en-us/dotnet/core/tools/csproj
Assembly Version Number
To get the assembly's "version", you should note that there are several types of versions:
AssemblyVersion:
Numeric value in the format major.minor.build.revision (for example, 2.4.0.0). The common language runtime uses this value to perform binding operations in strong-named assemblies.
Note: If the AssemblyInformationalVersionAttribute
attribute is not applied to an assembly, the version number specified by the AssemblyVersionAttribute
attribute is used by the Application.ProductVersion
, Application.UserAppDataPath
, and Application.UserAppDataRegistry
properties.
AssemblyFileVersion:
String value specifying the Win32 file version number. This normally defaults to the assembly version.
AssemblyInformationalVersion:
String value specifying version information that is not used by the common language runtime, such as a full product version number.
Note: If this attribute is applied to an assembly, the string it specifies can be obtained at run time by using the Application.ProductVersion
property. The string is also used in the path and registry key provided by the Application.UserAppDataPath
and Application.UserAppDataRegistry
properties.
Application.ProductVersion:
Defines additional version information for an assembly manifest.
You can find out about each one in greater detail on the official Microsoft Docs here -- or you can read about assemblies in general here:
Obtaining the different versions from the referenced assembly
// assembly version
Assembly.GetExecutingAssembly().GetName().Version.ToString();
// assembly version - by path
Assembly.LoadFile('your assembly file').GetName().Version.ToString();
// file version **this is likely what you are seeking**
FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
// product version
FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
Note that the above code snippet was taken from an answer to a similar SO question.
Parsing the .fsproj
file directly
There is also the option of just parsing the fsproj
file using XML. This option is intended for programmatically adding references or just checking files -- so it may not apply to your question, but it is here for completeness of the answer.
//using System.Xml.Linq
XDocument.Load(path).Descendants("PropertyGroup").Elements("Version").Single().Value;