What is the correct installation and reinstallation for the plugins

1 week ago
Please tell me some experience if you can.
1. I use vs2022  execute s-F5, and  I installed the plugin normally on this machine. After publishing it to iis, I hope not to install the same plugin again , Is this approach feasible?
2. Because I didn’t pay much attention to the correct Uninstall before, the database seems to be a bit confused. How should I check than install it correctly again?
1 week ago
You can use Up and Down methods to create and delete tables
In the Up method check if the table exists before trying to create
In the Down method check if the table exists before trying to delete it
- Although you may want to do other checks before blindly deleting the table of data

in below XXXX is your table class

using Nop.Core;
using Nop.Data.Extensions;
using Nop.Data.Mapping;
using Nop.Data.Migrations;
using Nop.Core.Domain.Catalog;
using Nop.Services.Configuration;
using Nop.Services.Stores;
using FluentMigrator.Expressions;
using FluentMigrator.Infrastructure;
using FluentMigrator.Builders.Delete.Table;

namespace Nop.Plugin.Your.Name.Data
{
    [NopMigration("2024/06/18 09:40:55:1687541", "Your.Name base schema")]
    public class SchemaMigration : FluentMigrator.Migration
    {
        protected IMigrationManager _migrationManager;
        protected ISettingService _settingService;
        protected IStoreService _storeService;
        protected IStoreContext _storeContext;

        public SchemaMigration(IMigrationManager migrationManager,
            ISettingService settingService,
            IStoreService storeService,
            IStoreContext storeContext)
        {
            _migrationManager = migrationManager;
            _settingService = settingService;
            _storeService = storeService;
            _storeContext = storeContext;
        }

        public override void Up()
        {
            try
            {
                if (!Schema.Schema("dbo").Table(NameCompatibilityManager.GetTableName(typeof(XXXX))).Exists())
                    Create.TableFor<XXXX>();

            }
            catch
            {
                // The Database Files may still exist if not deleted from last unistall
            }
        }

        public override void Down()
        {

            if (Schema.Schema("dbo").Table(NameCompatibilityManager.GetTableName(typeof(XXXX))).Exists())
                Delete.Table(NameCompatibilityManager.GetTableName(typeof(XXXX)));

        }
    }
}
1 week ago
Tks!
I tried to analyze the two tables. The left side shows a clean database plug-in that is normal (two more tables), and the right side shows an existing database that has been deleted(the2table). Then I re-executed upload restart install then crash. What else have I ignored?



.\Nop.Web.exe
RegisterRoutes
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.GetAuthenticationService(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.AuthenticateAsync(HttpContext context, String scheme)
   at Nop.Services.Authentication.CookieAuthenticationService.GetAuthenticatedCustomerAsync() in D:\code1\nopCommerce\src\Libraries\Nop.Services\Authentication\CookieAuthenticationService.cs:line 103
   at Nop.Web.Framework.WebWorkContext.SetCurrentCustomerAsync(Customer customer) in D:\code1\nopCommerce\src\Presentation\Nop.Web.Framework\WebWorkContext.cs:line 241
   at Nop.Web.Framework.WebWorkContext.GetCurrentCustomerAsync() in D:\code1\nopCommerce\src\Presentation\Nop.Web.Framework\WebWorkContext.cs:line 208
   at Nop.Web.Framework.WebWorkContext.GetWorkingLanguageAsync() in D:\code1\nopCommerce\src\Presentation\Nop.Web.Framework\WebWorkContext.cs:line 359
   at Nop.Services.Localization.LocalizationService.GetResourceAsync(String resourceKey) in D:\code1\nopCommerce\src\Libraries\Nop.Services\Localization\LocalizationService.cs:line 378
   at Nop.Services.Plugins.PluginService.InstallPluginsAsync() in D:\code1\nopCommerce\src\Libraries\Nop.Services\Plugins\PluginService.cs:line 522
   at Nop.Web.Framework.Infrastructure.Extensions.ApplicationBuilderExtensions.StartEngineAsync(IApplicationBuilder _) in D:\code1\nopCommerce\src\Presentation\Nop.Web.Framework\Infrastructure\Extensions\ApplicationBuilderExtensions.cs:line 69
   at Nop.Web.Program.Main(String[] args) in D:\code1\nopCommerce\src\Presentation\Nop.Web\Program.cs:line 46
   at Nop.Web.Program.<Main>(String[] args)


You can only continue to run after deleting xxxxx

{
  "InstalledPluginNames": [
    "Obsolete field, using only for compatibility"
  ],
  "InstalledPlugins": [
    {
      "SystemName": "Widgets.NivoSlider",
      "Version": "4.70.2"
    },
    {
      "SystemName": "DiscountRequirement.MustBeAssignedToCustomerRole",
      "Version": "4.70.3"
    }
  ],
  "PluginNamesToUninstall": [],
  "PluginNamesToDelete": [],
  "PluginNamesToInstall": [
    {
      "Item1": "ExternalAuth.xxxxx01",
      "Item2": "fdcb9d49-6ae2-475b-8583-d6d11380e4b4"
    },
    {
      "Item1": "Payments.xxxxx02",
      "Item2": "fdcb9d49-6ae2-475b-8583-d6d11380e4b4"
    }
  ]
}


1 week ago
log_gscc wrote:
RegisterRoutes
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions.GetAuthenticationService(HttpContext context)

Looks like a problem with one of the plugin install routines
Maybe not the database - could be RegisterRoutes
Did you try and debug the install routines ?
1 week ago
It seems that debugging takes a lot of time. I would like to ask a question first.

Which method is generally  used to install plugins after deploying to the client?
m1. Package everything before publishing and no longer install it.
or
m2. Clean the plugins before publishing and install plugins on the client.
1 week ago
If you are releasing a plugin to market then build and publish a release version
I publish the solution to a local directory
Then copy out the Plugin directory to build a  zip package
See this plugin for example https://www.nopcommerce.com/en/2checkout-payment-module

If you are building a system for a client then in most cases you would set it up with everything installed and tested - usually also using a full published version of the website including plugins

One problem maybe your database compatibility between development and production meaning you cannot restore a production database from backup or copy in the database files - in this case you need to do installs on the production server
1 week ago
Thank you for your analysis, this is what I want. It makes me feel confident to take the next step.
By the way
I also found a place in [dbo.setting]. Some parameters were generated by the previous installation. Do they need to be removed first? I am very suspicious?
1 week ago
If when you ran visual studio you installed the plugin to the production database then the production database will have the tables and the settings.
Then you just need to manually copy the plugin assembly output folder into the \Plugins folder in the production site, and modify the production plugins.json file, and restart the System.

Note that the plugin assembly folder in your local development is the one in the output path

<OutputPath>..\..\Presentation\Nop.Web\Plugins\{PLUGIN_OUTPUT_DIRECTORY}</OutputPath>