There are a number of differences in licensing NETCore or NET 8 applications, compared to full framework applications:
NuGet Package Installation in WPF Solutions
The Software Potential licensing solution depends on a series of code snippets that are inserted into the project being licensed via the various Software Potential NuGet packages. These code snippets are intended to simplify the wiring/configuration of the licensing mechanisms, including license store configuration etc.
In WPF solutions targeting NET 8 the NuGet packages are not included during the build process by default as happens with full framework projects. That is a problem as we depend on the included props and targets files to add our code snippets to the project.
Use IncludePackageReferencesDuringMarkupCompilation element
Adding the IncludePackageReferencesDuringMarkupCompilation
element to the csproj file ensures the required files are correctly included in the temporary project when the Software Potential NuGet packages are added.
Use RootNamespace element
Adding the <RootNamespace> element to the .csproj file ensures the root namespace is explicitly set for the project. This is necessary because the inner build in a WPF application build process does not currently honor the root namespace unless explicitly set in the csproj file. We depend on the Root Namespace being set correctly as this value is used to set the namespace in the SpProduct.cs file imported from our NuGet packages.
The csproj file should then look like the following WPF sample:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>net5.0-windows</TargetFramework> <UseWPF>true</UseWPF> <IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation> <RootNamespace>MyDemoApp</RootNamespace>
</PropertyGroup> <ItemGroup> <PackageReference Include="SoftwarePotential.Configuration.Local.SingleUser-852f9" Version="4.0.2045.22" /> <PackageReference Include="SoftwarePotential.Licensing-Demoapp_10" Version="1.0.1.8" /> <PackageReference Include="SoftwarePotential.Protection-852f9" Version="4.0.2045.22" /> </ItemGroup> </Project>
Configuration and Storage of Distributor Client
Distributor client configuration is managed via the SpAgent.Distributor.Customizations.cs file that is included in the Distributor NuGet package. This includes methods to configure the Distributor Base Uri and the application's current user that is required when implementing NamedUser feature in Distributor.
When targeting full framework, the default spAgent.Distributor.Customizaations.cs file automatically configures default storage for the Distributor BaseUri. This default storage configuration is not available for NETCore/NET5/NET6 applications and the vendor must now explicitly configure the BaseUri and its storage location.
Distributor BaseUri Configuration
To enable a licensed application to use Distributed resources, the Distributor Base Uri must be configured in the application. If the application end-user is to be able to set (and if necessary update) the Base URI setting it will need to be stored in a filesystem location that the Application is able to write to regardless of which user is active.
Unlike full framework projects, both the BaseUri and its storage location must be explicitly configured in an application targeting NetCore, NET5 or NET6. The Base Uri is then retrieved from its storage location via a callback in the partial method ConfigureStaticDistributorDiscovery()
.
If you already have a separate settings storage system in your application it makes sense to maintain the Distributor Base Uri in a similar fashion to other application settings. For example, if you add a setting within your application's configuration system, e.g. a MyApplicationSettings.DistributorUri property, you can adjust the the Distributor's configuration to obtain the Base Uri from your property by implementing ConfigureStaticDistributorDiscovery()
as follows:
static partial class SpAgent { static partial void ConfigureStaticDistributorDiscovery(Action<Func<Uri>> configure) { configure(() => { var result = new Uri(MyApplicationSettings.DistributorBaseUri); Debug.WriteLineIf(result == null, @"No Distributor BaseUri is currently Configured. For a Distributor to be used, your Externally Managed Settings will need to yield a non-null BaseUri"); return result; }); } }
Distributor Named User Configuration
As with full framework applications, the named user can be configured using the ConfigureNamedUserDiscovery()
method. For example:
static partial class SpAgent
{
static partial void ConfigureNamedUserDiscovery( Action<Func<string>> configure ) { configure( () => { return Environment.UserName; } ); }
}
Implementation
The SpAgent.Distributor.Customizations.cs file included in the solution via the Distributor client NuGet package contains an SpAgent partial class, with the ConfigureStaticDistributorDiscovery()
and ConfigureNamedUserDiscovery()
methods. If you implement your methods in this file, it may be overwritten on any NuGet package upgrade. Instead you should implement the methods in a new file in your application.
Comments
0 comments
Article is closed for comments.