[英]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 创建安装程序
以下是有关创建安装程序和您需要的扩展的一些附加资源。 根据您的 Visual Studio 版本,您可能需要另一个版本的扩展。
https://www.add-in-express.com/docs/net-msi-setup-project.php
您也可以使用“ Inno Setup ”来创建您的安装程序。 那里有很多示例代码。 基本上你需要做一些事情。
准备工作:创建您自己的工具,将信息写入您的 appSettings.json。 该exe应以arguments为参数,并根据这些arguments生成一个appSetting.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;
//示例代码。 创建安装程序屏幕。
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;
//示例代码。 在 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.