Forcing nopCommerce to Re-install Your Plugin on Build
When developing a plugin for nopCommerce, it is a bit of a hassle to uninstall and reinstall your plugin over and over as you add new features. Since nopCommerce stores the list of plugins and their statuses (installed, install-pending, etc), I thought it would be more convenient to force a re-install every time you build your project.
The key is to add a post-build script. I’ve implemented one in PowerShell:
<#
Forces your plugin to reinstall by modifying the web project's plugins.json. By Hobbes Pirakitti of Balta Development / VisionFriendly.com
To use:
1) Add this file to the root of your project as ForceReinstall.ps1
2) Customize the $pluginName variable below
2) To your .csproj, add the following
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="powershell $(ProjectDir)ForceReinstall.ps1" />
</Target>
#>
$pluginName = 'Misc.YourPluginName';
####### end configurable #######
$ErrorActionPreference = 'Stop';
cls;
$pluginJsonPath = Join-Path $MyInvocation.MyCommand.Source '..\..\..\Presentation\Nop.Web\App_Data\plugins.json' -Resolve;
$pluginString = Get-Content $pluginJsonPath -Raw;
$pluginJson = ConvertFrom-Json $pluginString;
$installedPlugins = [System.Collections.ArrayList]($pluginJson.InstalledPluginNames)
$installedPlugins.Remove($pluginName)
$pluginJson.InstalledPluginNames = $installedPlugins.ToArray();
if ($pluginJson.PluginNamesToInstall.Where({$_.Item1 -eq $pluginName}).Count -eq 0) {
$pluginsToInstall = [System.Collections.ArrayList]$pluginJson.PluginNamesToInstall;
$pluginsToInstall.Add(@{
"Item1" = $pluginName;
"Item2" = $null # "Customer GUID"
});
$pluginJson.PluginNamesToInstall = $pluginsToInstall;
}
$pluginJson | ConvertTo-Json -Depth 10 > $pluginJsonPath;
The instructions are in the script. Enjoy!
Comments