Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix 3.1.0

dotnet add package Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix --version 3.1.0
NuGet\Install-Package Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix -Version 3.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix" Version="3.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix --version 3.1.0
#r "nuget: Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix, 3.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix as a Cake Addin
#addin nuget:?package=Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix&version=3.1.0

// Install Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix as a Cake Tool
#tool nuget:?package=Phoenix.Functionality.LicenseProvider.ResourceAssembly.LittlePhoenix&version=3.1.0

Phoenix.Functionality.LicenseProvider

.NET .NET Standard .NET Framework
✔️ 2.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 LicenseConfigurations. 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 the LicenseResolver.

    <div style='padding:0.1em; border-style: solid; border-width: 0px; border-left-width: 10px; border-color: #37ff00; background-color: #37ff0020' > <span style='margin-left:1em; text-align:left'> <b>Information</b> </span> <br> <div style='margin-left:1em; margin-right:1em;'> All excluded assemblies will be completely overstepped when resolving licenses. </div> </div>

    <div style='padding:0.1em; border-style: solid; border-width: 0px; border-left-width: 10px; border-color: #ffd200; background-color: #ffd20020' > <span style='margin-left:1em; text-align:left'> <b>Hint</b> </span> <br> <div style='margin-left:1em; margin-right:1em;'> By default all dynamic assemblies and some common assemblies listed below are ignored. </div> </div>

    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()
	;

<div style='padding:0.1em; border-style: solid; border-width: 0px; border-left-width: 10px; border-color: #ffd200; background-color: #ffd20020' > <span style='margin-left:1em; text-align:left'> <b>Advice</b> </span> <br> <div style='margin-left:1em; margin-right:1em;'> Resource assemblies shouldn't reference the <i>Phoenix.Functionality.LicenseProvider</i>. </div> </div>

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 - v3.x
Product 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 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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.

Version Downloads Last updated
3.1.0 160 10/12/2023
3.0.0 348 8/15/2023
2.0.0 127 8/15/2023
1.2.0 123 8/15/2023
1.1.0 119 8/15/2023
1.0.0 118 8/15/2023