Phoenix.Functionality.LicenseProvider
1.5.0
See the version list below for details.
dotnet add package Phoenix.Functionality.LicenseProvider --version 1.5.0
NuGet\Install-Package Phoenix.Functionality.LicenseProvider -Version 1.5.0
<PackageReference Include="Phoenix.Functionality.LicenseProvider" Version="1.5.0" />
paket add Phoenix.Functionality.LicenseProvider --version 1.5.0
#r "nuget: Phoenix.Functionality.LicenseProvider, 1.5.0"
// Install Phoenix.Functionality.LicenseProvider as a Cake Addin #addin nuget:?package=Phoenix.Functionality.LicenseProvider&version=1.5.0 // Install Phoenix.Functionality.LicenseProvider as a Cake Tool #tool nuget:?package=Phoenix.Functionality.LicenseProvider&version=1.5.0
Phoenix.Functionality.LicenseProvider
.NET Framework | .NET Standard | .NET |
---|---|---|
✔️ 4.5.0 | ✔️ 2.0 | ✔️ 5.0 |
This project aims at providing license information for assemblies referenced by applications, services or even other assemblies.
Table of content
[toc]
General Information
When writing software, it is almost always necessary to make different license agreements from the work of other companies or single programmers, whose work is used in some fashion from the software being written, available.
Since it is easy to forget this, the Phoenix.Functionality.LicenseProvider has been created.
Concept
The Phoenix.Functionality.LicenseProvider provides licenses "on the fly" while the application is running. This is done by monitoring and matching the list of all currently loaded assemblies against a configurable collection of LicenseConfiguration
s. If an assembly matches one of those configurations, the appropriate license file will be written to the applications working or to a configurable other directory.
The idea is, that, instead of manually adding and updating licenses for all of the many projects software typical consists of, just a single Resource Assembly containing those license files should be created and maintained.
Usage
Set-Up
First step would be to add the Phoenix.Functionality.LicenseProvider NuGet package to your main project and then creating a new instance of the LicenseResolver
class. This class just needs to know which resource assemblies to analyze for license information and optionally where to safe the license files to. Both things are supplied via the LicenseResolverConfiguration
class.
// Below defined path is also the default path and could be omitted.
var licensesDirectory = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ".licenses"));
var resourceAssembly = typeof(SomeTypeFromTheAssembly).Assembly;
var configuration = new LicenseResolverConfiguration(licenseDirectory, resourceAssembly)
{
LogMissingLicensesToFile = _logMissing
};
var licenseResolver = new LicenseResolver(configuration);
Finally just call Start
on the newly created instance and licenses will be provided for all loaded assemblies.
licenseResolver.Start();
If you don't need the license provider to do its work anymore, you can call its Stop method.
licenseResolver.Stop();
If you prefer builder pattern, here you go:
var licenseResolver = LicenseResolver
.Construct()
.AddCurrentAssembly()
.AddAssemblyFromReference<SomeTypeFromTheAssembly>()
.WithDefaultOutputDirectory()
.DoNotExcludeAssemblies()
.DoNotLogMissingLicensesToFile()
.Build()
.Start()
;
In general the LicenseResolver
should be created and started early on in your application and never be stopped except when the application itself terminates.
LicenseResolverConfiguration
The LicenseResolverConfiguration
contains configuration information to be used by a LicenseResolver
. This are the options:
LicenseDirectory
The directory where the licenses will be saved to. Default is .licenses in the executing applications directory.
ResourceAssemblies
A collection of assemblies that will be searched for embedded xml license files.
ExcludedAssemblies
A collection of
ExcludedLicenseConfiguration
containing information about assemblies that will be ignored by theLicenseResolver
.❗ All excluded assemblies will be completely overstepped when resolving licenses.
❗ By default all dynamic assemblies and some common assemblies listed below are ignored.
Identifier Match mode system AssemblyNameMatchMode.StartsWith
microsoft.net AssemblyNameMatchMode.Contains
LogMissingLicensesToFile
Should the name of assemblies for which no license could be resolved be written to the file .missing.txt in the same directory where license are saved.
Resource Assemblies
A Resource Assembly in the world of the license provider is just a rather normal assembly that contains license information as embedded resource. The easiest way to provide such an assembly to the LicenseResolver
is by adding a single accessible type into the resource assembly.
/// <summary>
/// Just a class used to obtain a reference to its assembly.
/// </summary>
public sealed class Anchor { }
The whole assembly can now be added via this class:
var licenseResolver = LicenseResolver
.Construct()
.AddCurrentAssembly()
.AddAssemblyFromReference<Anchor>() // Here is the 'Anchor'.
.WithDefaultOutputDirectory()
.DoNotExcludeAssemblies()
.DoNotLogMissingLicensesToFile()
.Build()
;
❗ Resource assemblies shouldn't reference the Phoenix.Functionality.LicenseProvider
.
License Information
License information are simple XML files that must have the following structure.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<information
assemblyName="Autofac"
matchMode="Exact"
>
<license version="0.0.0" fileName="Autofac.txt">
The MIT License (MIT)
Copyright (c) 2014 Autofac Project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
</license>
</information>
The above example is a license configuration for Autofac.
Provide as many such files as are needed for all of the licensed software in play.
This XML contains all information needed for matching loaded assemblies and providing the license files.
- assemblyIdentifier
This is the identifier of the assembly for which license information should be provided.
- matchMode
This defines how the name of a loaded assembly is matched against the above assemblyIdentifier. Its values must equal those of the AssemblyNameMatchMode
enumeration. Possible values are:
Value | Description |
---|---|
Exact | The name of the assembly must match the assemblyIdentifier ignoring case. This is the default. |
Contains | The name of the assembly must contain with assemblyIdentifier. |
StartsWith | The name of the assembly must begin with assemblyIdentifier. |
EndsWith | The name of the assembly must end with assemblyIdentifier. |
RegEx | The name of the assembly must match the assemblyIdentifier that should be a regular expression. |
license (separat xml node)
- version
The version specifies from which version of the loaded assembly this license node is valid. If the license of some referenced assembly changes, simply add another license node with the corresponding version. This attribute can be omitted, in which case the version would be 0.0.0.
- fileName
The name of the file where the license will be saved to. If this is omitted, then the assemblyIdentifer suffixed by version with file extension .txt will be used instead.
- node value
This node value is the license text itself.
Authors
- Felix Leistner: v1.x
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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 | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. 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 | 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. |
-
.NETFramework 4.5
- System.ValueTuple (>= 4.5.0)
-
.NETStandard 2.0
- No dependencies.
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.