我们创建了一个“on”web应用程序,我的任务是为该应用程序创建一个安装程序,该应用程序将允许用户在SQLite或Server实现之间进行选择。我对如何做到这一点毫无头绪,也没有找到任何有明确方向的好文章。
我所做的就是在我的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;
}
发布于 2020-08-17 12:53:58
用Visual创建安装程序
下面是一些关于创建安装程序和您需要的扩展的额外资源。根据Visual的版本,您可能需要其他版本的扩展。
https://www.add-in-express.com/docs/net-msi-setup-project.php
发布于 2020-08-23 08:22:48
您也可以使用"Inno设置“来创建安装程序。这里有大量的示例代码。基本上你需要做几件事。
准备:创建您自己的工具将信息写入您的appSettings.json。exe应该接受参数作为参数,并根据这些参数生成一个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控件以允许Server连接中的用户键
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;
https://stackoverflow.com/questions/63420257
复制相似问题