繁体   English   中英

如何为 ASP.NET Core / Angular web 应用程序创建安装程序?

[英]How to create installer for ASP.NET Core / Angular web app?

我们创建了一个“本地”web 应用程序,我的任务是为该应用程序创建一个安装程序,以编程方式允许用户在 SQLite 或 Z9778840A0100CB30C982876741B0 服务器实现之间进行选择。 我对如何做到这一点零线索,也没有找到任何有明确方向的好文章。

我所做的只是在我的Startup.cs文件中编写以下代码,以在我的appsettings.json文件中的两个连接字符串之间进行选择。 有谁知道创建/实现安装程序的最佳方法? 这种事情有开源解决方案吗? 我对这个感到很失落......

protected virtual IServiceCollection ConfigureDbContext(IServiceCollection services)
        {
            var isSqlServerConnection = Configuration.GetValue<bool>("UseSql");

            if (isSqlServerConnection)
            {
                services.AddDbContext<SecurityDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("Default")).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll),
                ServiceLifetime.Transient);

                services.AddDbContext<StorageContext>(options =>
                options.UseSqlite(Configuration.GetConnectionString("Default")).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking),
                ServiceLifetime.Transient);
            }
            else
            {
                services.AddDbContext<SecurityDbContext>(options =>
                options.UseSqlite(Configuration.GetConnectionString("Sqlite")).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll),
                ServiceLifetime.Transient);

                services.AddDbContext<StorageContext>(options =>
                options.UseSqlite(Configuration.GetConnectionString("Sqlite")).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
             , ServiceLifetime.Transient);
            }

            return services;
        }

使用 Visual Studio 创建安装程序

  1. 关闭除一个 Visual Studio 实例之外的所有实例。
  2. 在正在运行的实例中,访问菜单工具->扩展和更新。
  3. 在该对话框中,选择 Online->Visual Studio Marketplace->Tools->Setup & Deployment。
  4. 从出现的列表中,select Microsoft Visual Studio 2017 安装程序项目。
  5. 安装后,关闭并重新启动 Visual Studio。 Go 到 File->New Project 并搜索单词 Installer。 如果您看到如下所示的列表,您将知道您安装了正确的模板:

与示例

  1. 使用安装项目创建安装程序以满足您的需求。 例如,您可以在安装程序上轻松创建一个页面,用户选择 SQLite 或 SQL 服务器作为支持的数据。

以下是有关创建安装程序和您需要的扩展的一些附加资源。 根据您的 Visual Studio 版本,您可能需要另一个版本的扩展。

https://marketplace.visualstudio.com/items?itemName=VisualStudioClient.MicrosoftVisualStudio2017InstallerProjects

https://codeteddy.com/2016/04/04/creating-an-msi-package-for-c-windows-application-using-a-visual-studio-setup-project/

https://www.add-in-express.com/docs/net-msi-setup-project.php

您也可以使用“ Inno Setup ”来创建您的安装程序。 那里有很多示例代码。 基本上你需要做一些事情。

准备工作:创建您自己的工具,将信息写入您的 appSettings.json。 该exe应以arguments为参数,并根据这些arguments生成一个appSetting.json文件。

  1. 在 inno setup files 部分,设置构建工件的路径,以及您自己的 json 生成工具。

//示例代码

[Files]
    Source: bin\*; DestDir: {app}\bin; Flags: recursesubdirs uninsneveruninstall; Components: Main
    Source: Utilities\AppSettingGenerator.exe; DestDir: {app}\Utilities\AppSettingGenerator.exe; Components: " Main"; Tasks: ; Flags: uninsneveruninstall; 
  1. 创建一个屏幕让用户 select 数据库引擎、sqllite 或 Sql 服务器。
  2. 创建另一个屏幕来设置连接字符串。

//示例代码。 创建安装程序屏幕。

procedure FormCreatePage(PreviousPageId: Integer);
begin
    pgeInstallType := CreateInputOptionPage(    wpWelcome,
                                                'Select Installation Type',
                                                'Which type of installation do you want to run?',
                                                'Select the type of installation that you would like to run. Click Next when you are ready to continue.',
                                                true,
                                                false
                                             );

    pgeInstallType.Add('Sqllite');
    pgeInstallType.Add('Sql Server');

    pgeInstallType.Values[0] := true;

    
    pgeInput1 := CreateCustomPage(  PreviousPageId,
                                    'Configure Sql Server Connection',
                                    'Please verify the details for those sections highlighted in red before continuing.'
                                 );

    pgeInput2 := CreateCustomPage(  pgeInput1.ID,
                                    'Configure Sql lite Connection',
                                    'Please verify the details for those sections highlighted in red before continuing.'
                                 );
end;

//示例代码。 创建 UI 控件以让用户键入 Sql 服务器连接

pnlSQL := TPanel.Create(pgeInput1);
    with pnlSQL do
        begin
            Parent := pgeInput1.Surface;
            Left := ScaleX(0);
            Top := ScaleY(30);
            Width := ScaleX(413);
            Height := ScaleY(125);
            BevelInner := bvLowered;
        end;

    { lblPnlSQL }
    lblPnlSQL := TLabel.Create(pgeInput1);
    with lblPnlSQL do
        begin
            Parent := pnlSQL;
            Left := ScaleX(340);
            Top := ScaleY(5);
            Width := ScaleX(70);
            Height := ScaleY(13);
            AutoSize := False;
            Caption := 'SQL Server';
            Font.Height := ScaleY(-11);
            Font.Style := [fsBold, fsItalic];
        end;

    { lblSrvName }
    lblSrvName := TLabel.Create(pgeInput1);
    with lblSrvName do
        begin
            Parent := pnlSQL;
            Left := ScaleX(5);
            Top := ScaleY(5);
            Width := ScaleX(66);
            Height := ScaleY(13);
            Caption := 'Server Name:';
            Font.Height := ScaleY(-11);
        end;

    { lblUserID }
    lblUserID := TLabel.Create(pgeInput1);
    with lblUserID do
        begin
            Parent := pnlSQL;
            Left := ScaleX(5);
            Top := ScaleY(25);
            Width := ScaleX(40);
            Height := ScaleY(13);
            Caption := 'User ID:';
            Font.Height := ScaleY(-11);
        end;

    { lblPassword }
    lblPassword := TLabel.Create(pgeInput1);
    with lblPassword do
        begin
            Parent := pnlSQL;
            Left := ScaleX(5);
            Top := ScaleY(46);
            Width := ScaleX(50);
            Height := ScaleY(13);
            Caption := 'Password:';
            Font.Height := ScaleY(-11);
        end;

    { lblDBName }
    lblDBName := TLabel.Create(pgeInput1);
    with lblDBName do
        begin
            Parent := pnlSQL;
            Left := ScaleX(5);
            Top := ScaleY(67);
            Width := ScaleX(80);
            Height := ScaleY(13);
            Caption := 'Database Name:';
            Font.Height := ScaleY(-11);
        end;
  1. 在安装程序屏幕上输入参数后调用您的 appsettingGenerator 工具。

//示例代码。 在 nextbuttonClick 处调用,检查当前页面是否正确

function NextButtonClick(CurPageID: Integer): Boolean; 
var     i: Integer; 
begin 
  if CurPageID = pgeInput2.ID then      
  begin                                 
    RunExe(gUtilAppsettingGenerator,' -dbuid "' + txtUserID.Text + '"
     -dbpass "' + txtPassword.Text + '" -c "server=' + txtSrvName.Text + ';database='    + txtDBName.Text + '" -dbinst "' + txtDSN.Text + '"', ewWaitUntilTerminated, true); 

end;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM