There may be situations where it is necessary to merge the SpAgent standard runtime assemblies with a protected or licensed assembly in an application.
Merging SpAgent assemblies using ILRepack
The following is our recommended approach to merging the SpAgent Standard assemblies with the licensed assembly using ILRepak. This uses the ILRepack.MSBuild.Task approach outlined in the following post by Jamie Phillips: Using ILRepack with dotnet core SDK and dotnet Standard
The steps involved are:
- Install NuGet packages
- Configure Release configuration settings
- Add an ILMerge MSBuild target
Install NuGet packages:
Install the following packages in addition to the Software Potential packages required for either protection or licensing
- ILRepack.MSBuild.Task package (https://www.nuget.org/packages/ILRepack.MSBuild.Task/)
The following are sample Project References for the Software Potential and ILMerge.MSBuild.Task packages:
<ItemGroup> <PackageReference Include="ILRepack.MSBuild.Task" Version="2.0.13" /> <PackageReference Include="SoftwarePotential.Configuration.Local.SingleUser-90c24" Version="4.0.2006.12" /> <PackageReference Include="SoftwarePotential.Licensing-Demoapp_10" Version="1.0.1.8" /> <PackageReference Include="SoftwarePotential.Protection-90c24" Version="4.0.2006.12" /> <PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0004" /> </ItemGroup>
Release Configuration Settings
No PDB Generation
Set the Release configuration to NOT generate PDB. To do this in Visual Studio Solution Explorer
- Select the project and then right click to get Properties
- Select Build - > Advanced
- Set Debugging Information to None
Platform Target
You need to set the Platform Target to AnyCPU if you intend targetting any x64 .NET Core RID
Alternatively you can manually add the following Property Group to your csproj file
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <DebugType>none</DebugType> <DebugSymbols>false</DebugSymbols> <PlatformTarget>AnyCPU</PlatformTarget> </PropertyGroup>
ILRepack MSBuild target
Add an ILRepack MSBuild target to your project to configure ILRepack merge process. The target specifies:
- The location of the assemblies to be merged in $(WorkingDirectory)
- SpAgent assemblies to be merged (typically done using an Sp.Agent.*.dll wildcard)
- Target licensed assembly with which the SpAgent assemblies are to be merged
This target should also delete all the SpAgent assemblies once they are merged with the target assembly.
Working Directory
The WorkingDirectory specifies where the merge process will take place and where the merged final assembly will be created. This will depend on whether the merge is to happen after Build or after Publish:
- Build: The working directory is the build output directory
$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework) - Publish: The working directory is the final publish directory for the target Framework (2.x or 3.x) and the RuntimeIdentifier (RID)
$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish
The following is a sample target to trigger merge after Publish target:
<Target Name="ILRepack" AfterTargets="Publish" Condition="'$(Configuration)' == 'Release'"> <PropertyGroup> <!--SET TO THE APPROPRIATE BUILD OR PUBLISH FOLDER DEPENDING ON THE AFTERTARGETS VALUE--> <WorkingDirectory>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish</WorkingDirectory> </PropertyGroup> <Message Text="Working Directory: $(WorkingDirectory)" Importance="high"/> <ItemGroup> <InputAssemblies Include="Sp.Agent.dll" /> <InputAssemblies Include="Sp.Agent.90c24.dll" /> <InputAssemblies Include="Sp.Agent.Local.dll" /> <InputAssemblies Include="Sp.Agent.Local.90c24.dll" /> </ItemGroup> <ItemGroup> <InternalizeExcludeAssemblies></InternalizeExcludeAssemblies> </ItemGroup> <Message Text="MERGING ASSEMBLIES: @(InputAssemblies) into $(AssemblyName).dll" Importance="High" /> <ILRepack OutputType="$(OutputType)" MainAssembly="$(AssemblyName).dll" OutputAssembly="$(AssemblyName).dll" InputAssemblies="@(InputAssemblies)" InternalizeExcludeAssemblies="@(InternalizeExcludeAssemblies)" WorkingDirectory="$(WorkingDirectory)"/> <!--Delete the SpAgent assemblies when merge is completed--> <ItemGroup> <FilesToDelete Include="$(WorkingDirectory)\Sp.Agent*.dll"/> </ItemGroup> <Message Text="Assemblies to delete: @(FilesToDelete)" Importance="High"/> <Delete Files="@(FilesToDelete)" /> </Target>
Comments
0 comments
Article is closed for comments.