Skip to Content
New release 12 available 🎉

Lic MSBuild Task Server

The Lic task runs the lic command line from an MSBuild project, so a build can generate and sign licenses with the same properties as the command line.

The Lic task lives in Babel.Build.dll, the same assembly that provides the obfuscator’s Babel task. It builds a lic command line from its properties and items and runs lic.exe, so everything the Reference describes is available from a project file. Two things use it:

  • Your own MSBuild projects, for example to issue a test license for the application under test, or to generate customer licenses from a build server.
  • .lcproj project files, which lic --makeproject writes from a command line and lic --project runs again; see Project Files.

Registering the Task

Reference the task assembly with a UsingTask element that points to Babel.Build.dll. In the Babel zip packages it is in the MSBuild folder, so with BabelDir set to the folder where babel_net472_<version>.zip was extracted:

<UsingTask TaskName="Lic" AssemblyFile="$(BabelDir)\MSBuild\Babel.Build.dll" />

The task runs lic.exe from the folder set by LicDirectory. Without it, the task looks next to Babel.Build.dll and then in the folder named by the BABEL_INSTALL_DIRECTORY environment variable. Because lic.exe sits in the root of the extracted zip package, not in its MSBuild folder, set LicDirectory to that root, as the example below does.

With LicDirectory set, the task runs lic.exe, which requires Windows. The babel_net80, babel_net90 and babel_net100 zip packages also contain MSBuild/Babel.Build.dll and lic.dll: when MSBuild runs under the dotnet host and the task finds lic.dll without LicDirectory, it runs it through dotnet. Wherever only the Babel Licensing Tool is available, run lic from an Exec task instead; the switches are the same.

A Complete Example

The project below generates a signed license for the built assembly after the build. Licensee, product, features, fields and restrictions are MSBuild items whose metadata become the key=value pairs of the corresponding switches:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTask TaskName="Lic" AssemblyFile="$(BabelDir)\MSBuild\Babel.Build.dll" /> <PropertyGroup> <BabelDir>C:\Tools\babel_net472</BabelDir> <LicenseKeyFile>$(MSBuildProjectDirectory)\keys\signing.pem</LicenseKeyFile> <LicenseOutputFile>$(OutDir)MyApp.licenses</LicenseOutputFile> </PropertyGroup> <ItemGroup> <Licensee Include="Contoso"> <Id>C-1001</Id> <Company>Contoso Ltd</Company> <Email>info@contoso.com</Email> </Licensee> <Product Include="MyApp"> <Id>MYAPP</Id> <Version>2.1</Version> <Url>https://contoso.example</Url> </Product> <Feature Include="Pro"> <Data>1</Data> </Feature> <Field Include="Seats"> <Value>25</Value> </Field> <Restriction Include="Trial"> <TrialDays>30</TrialDays> <RunInstances>2</RunInstances> </Restriction> <Restriction Include="Hardware"> <HardwareKey>GPHI6-128DI-6196C-KN5LV-BCDRE</HardwareKey> </Restriction> </ItemGroup> <Target Name="MakeLicense" AfterTargets="Build"> <Lic LicDirectory="$(BabelDir)" InputFile="$(TargetPath)" OutputFile="$(LicenseOutputFile)" KeyFile="$(LicenseKeyFile)" Sign="rsa" ExpireDate="365" Encoding="utf-8" Licensee="@(Licensee)" Product="@(Product)" Features="@(Feature)" Fields="@(Field)" Restrictions="@(Restriction)" /> </Target> </Project>

This is equivalent to the command line:

lic MyApp.dll --keyfile keys\signing.pem --sign rsa --expiredate 365 --encoding utf-8 --licensee name=Contoso --licensee id=C-1001 --licensee company="Contoso Ltd" --licensee email=info@contoso.com --product name=MyApp --product id=MYAPP --product version=2.1 --product url=https://contoso.example --feature def=... --field def=... --trial days=30 --trial instances=2 --hardware key=GPHI6-128DI-6196C-KN5LV-BCDRE --output MyApp.licenses

Set ProvideCommandLineArgs="true" and read the CommandLineArgs output item to see the exact command line the task built.

Task Properties

Each property maps to the switch of the same meaning in the Reference. Scalar properties take a string; item properties take an item list.

Input and output

PropertySwitchDescription
InputFilefirst argumentThe assembly to license, or the license file to update or verify.
Project--projectAn .lcproj project file whose settings are applied first.
Assemblies--assemblyItems naming other assemblies, by file or by name, to add to the license.
OutputFile--outputThe output license file.
Format--formatxml, serial, base32 or ascii; also json or ndjson for the task’s console output.
Encoding--encodingCharacter encoding of the XML license file.
XmlDeclaration--[no]xmldeclarationWhether to write the XML declaration.
GenerateKeyInfo--[no]keyinfoWhether to include the public key information in the RSA signature element.
MakeProject--makeprojectWrite an .lcproj project file with the effective settings.
GenerateLogFile, LogFile--logfileRedirect the console output to a log file, named by LogFile or by the output file.

Keys and signature

PropertySwitchDescription
KeyFile--keyfilePEM, SNK or PFX key file.
KeyContainer--keynameKey container name.
KeyPwd--keypwdPassword of a PFX key file.
KeyGen--keygenrsa or ecdsa: generate a new key pair into KeyFile.
KeySize--keysizeKey size for KeyGen.
Sign--signSign the license: rsa, ecdsa or dsig. The license is unsigned when this property is empty.
Verify--verifytrue to verify the signature of InputFile instead of generating a license.

License content

PropertySwitchDescription
LicenseId--idLicense identifier.
LicenseType--typeLicense type text.
IssueDate--issuedateIssue date.
ExpireDate--expiredateExpiration date, or a number of days.
Licensee--licenseeOne item: Include is the name; metadata Id, Name, Company, Email.
Product--productOne item: Include is the name; metadata Id, Name, Version, Copyright, Description, Url.
Components--componentItems naming the licensed components.
Features--featureItems: Include is a file path, or the feature name with metadata Id, Name, Description, Key, Data, ExpireDate, SupportExpireDate.
Fields--fieldItems: Include is a file path, or the field name with metadata Id, Name, Value.
Restrictionsrestriction switchesItems whose Include selects the restriction type; see Restriction items.
Update--updateUpdate the license with the given identifier, or all, in InputFile.

Restriction items

The Include value of a Restriction item selects the switch, case-insensitively, and the metadata supply its key=value pairs. Any other Include value is treated as a custom restriction name, passed to --restriction with each metadata as a pair; custom types need an extension assembly listed in Register.

IncludeSwitchMetadata
Trial--trialTrialDays (or ExpireDays), RunCount, RunInstances (or AllowedInstances), RunTime (or UsageTime), Terms.
Hardware--hardwareHardwareKey (or Key), Data.
Domain--domainName, Role.
Usage--usageType, CanRunOnVirtualMachine (or CanRunInVirtualEnvironment), ProcessList.
Beta--betaBuildType, RecentChanges, Description.

Hardware identification

PropertySwitchDescription
HardwareId--hardwareidItems naming the components to derive the hardware key from.
Salt--saltSalt for the hardware key.
ShowHardwareInfo--showhardwareinfoPrint the hardware information of the build machine.

Tool and diagnostics

PropertySwitchDescription
License--licenseItems with the paths of the tool’s own license file or search folders.
LicDirectoryFolder containing the lic.exe to run, such as the root of the extracted Babel zip package.
Register--registerItems naming extension assemblies to load.
ShowLogo--[no]logoWhether to print the banner.
VerboseLevel--verboseConsole verbosity.
NoConfiguration--noconfigSkip the tool’s default configuration.
ProvideCommandLineArgstrue to expose the generated command line in the CommandLineArgs output item.

Project Files

An .lcproj file is an ordinary MSBuild project that registers the Lic task and calls it from a MakeLicense target, with the settings of one license generation. lic --makeproject writes one from the switches of the current command line, next to the output file unless a name is given, and still generates the license. lic --project reads such a file and runs it, applying any further switches on top, without invoking MSBuild; the file can also be built with msbuild or dotnet build on a machine where the task is registered.

lic MyApp.dll --keyfile keys.pem --sign --licensee name=Contoso --expiredate 365 --output MyApp.licenses --makeproject MyApp.lcproj lic --project MyApp.lcproj --licensee name="Fabrikam" --output Fabrikam.licenses

The project file keeps a reproducible record of how a license was produced, and gives a customer-specific generation a single file you can version, review and rerun.

Last updated on