Spkl setup for multiple assemblies
In several of my previous posts (Add Sparkle XRM to a Webresources project or Deploying Web resources or Plugins with Azure DevOps Pipeline), I mentioned Sparkle XRM for webresource deployment. I am currently in a project where we have several plugin assemblies (as I described here), one per entity. I struggled to set up spkl to be able to deploy all of those at once. After figuring out how it works I thought it might be helpful for others to know as well. So in this blog post you will learn how to create a Spkl setup for multiple assemblies.
Big shout out to Scott Durow (Twitter and LinkeIn) for creating the tool and helping me figure this out.
Problem
As I described in my post about the folder structure I use I have had my spkl config within my front-end folder. This was the case since I only used it for the deployment of Webresources so far. Being where it is (in the subfolder under front-end) spkl wasn’t able to find the correct configuration when I tried to run the deploy-plugins Bat-file, because all the plugins were in a folder somewhere completely different in my structure.
Solution
I could have created several spkl projects for different parts of the solution (one for webresources and one for every plugin assembly). Since I am a lazy person I would like to be able to run one bat file and it automagically deploys all the assemblies. Luckily spkl does provide this functionality.
What is needed is to have spkl in the root folder as well ass creating our own, slightly modified, bat files.
Folder structure
Let’s take another look at the folder structure I described in the mentioned post. I only show the necessary part.
root ├── Development │ ├── Back-end │ │ ├── Plugins │ ├── Front-end │ │ ├── spkl │ │ ├── ts │ │ ├── Webresources │ │ │ ├── html │ │ │ ├── css │ │ │ ├── images │ │ │ ├── js
As you can see there is a spkl folder within the “Front-end” folder. If we have spkl there it is not directly able to find the plugins under “Back-end”. For sure you could configure it to look over there as well, but then the setup will get inconsistent since spkl is installed in the “front-end” folder and does stuff in the “back-end” folder as well.
Therefore we will move it to the root of the Development folder. Like this:
root ├── Development │ ├── Back-end │ │ ├── Plugins │ ├── Front-end │ │ ├── ts │ │ ├── Webresources │ │ │ ├── html │ │ │ ├── css │ │ │ ├── images │ │ │ ├── js │ ├── spkl
Config files
The next step is to create a “spkl.json” in the root of every assembly folder (which would be placed under “Back-end/Plugins”).
This config file is actually very generic and will be the same for every plugin project you have in your solution. It should look like this:
{ "plugins": [ { "profile": "default,debug", "assemblypath": "bin\\Debug" }, { "profile": "release", "assemblypath": "bin\\Release" } ] }
Since we moved the spkl project we have to copy the spkl.json config from there to the front-end folder to make the webresource deployment working again and make the spkl setup for multiple assemblies more complete. Here the root part of the config should be changed from “../Webresources/” to “Webresources/”.
If you would like spkl to add new plugins and steps to a certain solution you only have to add “solution:<solutionname>” to every profile. Here is an example
{ "plugins": [ { "profile": "default,debug", "assemblypath": "bin\\Debug", "solution": "DemoSolution" }, { "profile": "release", "assemblypath": "bin\\Release", "solution": "DemoSolution" } ] }
Bat-files
To begin with, we create a new folder called “custom-bats” in our spkl folder. Next we copy the files “deploy-plugins.bat” and “deploy-webresources.bat” from the spkl/spkl folder to the spkl/custom-bats folder.
All we have to change in the “deploy-plugins.bat” file is the path part of the spkl command on line 12. In the file which comes with spkl we only have
"%cd%\.."
What we have to do is to go two folders up and then into the Back-end/Plugins folder where spkl should search for all the config files and deploy the Plugins accordingly. The whole file should look like this
@echo off set package_root=..\..\ REM Find the spkl in the package folder (irrespective of version) For /R %package_root% %%G IN (spkl.exe) do ( IF EXIST "%%G" (set spkl_path=%%G goto :continue) ) :continue @echo Using '%spkl_path%' REM spkl plugins [path] [connection-string] [/p:release] "%spkl_path%" plugins "%cd%\..\..\Back-end\Plugins" %* if errorlevel 1 ( echo Error Code=%errorlevel% exit /b %errorlevel% ) pause
With this configuration, spkl will take your debug build when deploying. If you would like to use the release build you have to add “/p:release” to the end of the spkl command on line 12. I usually create a separate bat file that I use for release deployment.
For the Webresources bat, we have to do the same. Here we replace the path so that it points to the front-end folder. The file should look like this.
@echo off set package_root=..\..\ REM Find the spkl in the package folder (irrespective of version) For /R %package_root% %%G IN (spkl.exe) do ( IF EXIST "%%G" (set spkl_path=%%G goto :continue) ) :continue @echo Using '%spkl_path%' REM spkl webresources [path] [connection-string] "%spkl_path%" webresources "%cd%\..\..\front-end" %* if errorlevel 1 ( echo Error Code=%errorlevel% exit /b %errorlevel% ) pause
If you are working against an on-Premises installation of Dynamics you have to add the flag “-l” to the spkl command on line 12 of the bat-file.
All the bat files should require to press any button when the run is ready. When your cmd just closes there was some error. You can run the command in the cmd directly to see the errors.
Conclusion
Now you know how to create an Spkl setup for multiple assemblies. If one understands how spkl works it’s not a very big deal to create a correct setup, to be honest.
I hope the post helped you. Please let me know if you have any further questions.
You can also subscribe and get new blog posts emailed to you directly.
Hey Benedikt,
Thanks for all your posts they’ve been really helpful in terms of making my projects much more consistent. Any chance you could do a blog post on your method of creating a plugin/several plugins within the context of your folder structure?
Thanks, James.
Hej James,
I am glad to hear that you liked my posts.
Sure, I can absolutely write something together around this topic. I have already picked the topic for my next post, but let me do it after that.