UoN.VersionInformation
2.0.0
dotnet add package UoN.VersionInformation --version 2.0.0
NuGet\Install-Package UoN.VersionInformation -Version 2.0.0
<PackageReference Include="UoN.VersionInformation" Version="2.0.0" />
paket add UoN.VersionInformation --version 2.0.0
#r "nuget: UoN.VersionInformation, 2.0.0"
// Install UoN.VersionInformation as a Cake Addin #addin nuget:?package=UoN.VersionInformation&version=2.0.0 // Install UoN.VersionInformation as a Cake Tool #tool nuget:?package=UoN.VersionInformation&version=2.0.0
UoN.VersionInformation
What is it?
A pluggable service for retrieving version information from .NET Object types.
Really it just provides a simple system for
- optionally taking an input object
- executing something that returns a simple data object, possibly based on the input object
- returning the result.
We just happen to use it for version information.
It includes some basic providers which don't add dependencies beyond the NetStandard.Library
.
Dependency Injection
For Dependency Injection in a .NET Core IServicesCollection
compatible environment,
see UoN.VersionInformation.DependencyInjection
What are its features?
Version Information Service
This is the core service.
It provides two main methods for use, as well as a specific helper for the most common use case. It also accepts some configuration.
- The Service can always give you the
AssemblyInformationalVersion
of the current application's Entry Assembly, usingEntryAssemblyAsync()
. - It can execute a pre-configured Provider (optionally with an input object) identified by a string key using
ByKeyAsync()
. - It can execute arbitrary Providers passed to it, or pre-configured Providers assigned to handle specific .NET Types using
FromSourceAsync()
.
Version Information Providers
The package provides three basic implementations of IVersionInformationProvider
.
Further implementations are encouraged, based on where you want to get version information from, and the output object structure you would like it to have.
The implementations in this package only depend on NetStandard.Library
.
AssemblyInformationalVersionProvider
This provides the behaviour of EntryAssemblyAsync()
. It is also by default configured as the Type Handler for .NET Assembly
objects.
It simply gets the AssemblyInformationalVersion
of a given .NET Assembly and returns it as a string.
You're unlikely to use this directly because you can leave it configured as a Type Handler, and simply pass assemblies directly to FromSourceAsync()
.
// this service usage:
service.EntryAssemblyAsync();
service.FromSourceAsync(MyAssembly);
// is equivalent to
service.FromSourceAsync(new AssemblyInformationalVersionProvider());
service.FromSourceAsync(new AssemblyInformationalVersionProvider(MyAssembly));
FileContentProvider
This is a very basic Provider which reads all the content from a file, and returns it as a string. It's suitable for use as a base class by other file-based Providers.
If you wish to use it, it can be useful to configure it either as the default Type Handler for string
s, or to configure it as a Key Handler.
// this is fine
service.FromSourceAsync(new FileContentProvider("path/to/file.txt"));
service.FromSourceAsync("my string"); // this still passes through the string value
// this is simpler if you want to use it on multiple files later
service.TypeHandlers.Add(typeof(string), new FileContentProvider());
service.FromSourceAsync("path/to/file.txt"); // GOOD - now sent to the FileContentProvider
service.FromSourceAsync("my string"); // BAD - also sent to the provider and assumed to be a file path...
// this is safer than above
service.KeyHandlers.Add("file", new FileContentProvider()); // maybe use enums for keys in your code ;)
service.ByKeyAsync("file", "path/to/file.txt");
service.FromSourceAsync("my string"); //absolutely fine
KeyValueFileProvider
This is a very naive provider for reading Key Value pairs from text files.
It is recommended to use a Provider for a real file format such as JSON, YAML, INI etc...
This implementation is here for convenience and requires no dependencies outside of NetStandard.Library
.
Each line of the file is considered a new Key Value pair, The first =
encountered splits the key from the value. That's it.
Keys cannot contain delimiters (obviously) but values can.
The delimiter is configurable, but defaults to =
.
// File:
// -----
// Key 1:=Value
// Key2=Value:With=
var provider = new KeyValueFileProvider("path/to/file.txt");
// { "Key 1:": "Value", "Key2": "Value:With=" }
version.FromSourceAsync(provider);
provider.Delimiter = ":";
// { "Key 1": "=Value", "Key2=Value": "With=" }
version.FromSourceAsync(provider);
Dependencies
The library targets netstandard1.5
, due to its use of Assembly.GetEntryAssembly()
.
This still enables use in applications targeting .NET 4.61
and newer, and .NET Core 1.0
.
For full implementation support see here.
Building from source
We recommend building with the dotnet
cli, but since the package targets netstandard1.5
and depends only on NetStandard.Library
, you should be able to build it in any tooling that supports those requirements.
- Have the .NET Core SDK
dotnet build
- Optionally
dotnet pack
- Reference the resulting assembly, or NuGet package.
Contributing
If you make useful providers that depend only on NetStandard.Library
, raise a PR and they can be added to the base package.
If there are issues open, please feel free to make pull requests for them, and they will be reviewed.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.5 is compatible. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.5
- NETStandard.Library (>= 1.6.1)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on UoN.VersionInformation:
Package | Downloads |
---|---|
UoN.AspNetCore.VersionMiddleware
Version middleware for ASP.NET Core, allows exposing version information via an endpoint. |
|
UoN.VersionInformation.DependencyInjection
`IServiceCollection` extensions for using `UoN.VersionInformation` with `Microsoft.Extensions.DependencyInjection`. |
GitHub repositories
This package is not used by any popular GitHub repositories.
This release is mostly for branding and versioning consistency due to updates to related packages:
- Updated package metadata, to reflect:
- newer best practice for NuGet
- source authorship and ownership
- repository structure changes
- Version bumped for consistency with the directly related packages