C# 如何为ASP.NET Core/Angular web应用程序创建安装程序?
我们创建了一个“on-prem”web应用程序,我的任务是为该应用程序创建一个安装程序,该程序将以编程方式允许用户在SQLite或SQL Server实现之间进行选择。我对如何做到这一点没有任何线索,也没有找到任何方向明确的好文章 我所做的就是在我的C# 如何为ASP.NET Core/Angular web应用程序创建安装程序?,c#,.net,sql-server,deployment,C#,.net,Sql Server,Deployment,我们创建了一个“on-prem”web应用程序,我的任务是为该应用程序创建一个安装程序,该程序将以编程方式允许用户在SQLite或SQL Server实现之间进行选择。我对如何做到这一点没有任何线索,也没有找到任何方向明确的好文章 我所做的就是在我的Startup.cs文件中编写以下代码,以便在我的appsettings.json文件中的两个连接字符串之间进行选择。有人知道创建/实现安装程序的最佳方法吗?这类事情有开源解决方案吗?在这件事上我感到很失落 protected virtual ISe
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;
}
受保护的虚拟IServiceCollection ConfigureDbContext(IServiceCollection服务)
{
var isSqlServerConnection=Configuration.GetValue(“UseSql”);
if(isSqlServerConnection)
{
services.AddDbContext(选项=>
options.UseSqlServer(Configuration.GetConnectionString(“默认”)).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll),
服务寿命(瞬时);
services.AddDbContext(选项=>
options.UseSqlite(Configuration.GetConnectionString(“默认”)).UseQueryTrackingBehavior(QueryTrackingBehavior.NotTracking),
服务寿命(瞬时);
}
其他的
{
services.AddDbContext(选项=>
options.UseSqlite(Configuration.GetConnectionString(“Sqlite”)).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll),
服务寿命(瞬时);
services.AddDbContext(选项=>
options.UseSqlite(Configuration.GetConnectionString(“Sqlite”)).UseQueryTrackingBehavior(QueryTrackingBehavior.NotTracking)
,服务寿命。瞬态);
}
返回服务;
}
使用Visual Studio创建安装程序
[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 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;
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;
到目前为止你看了什么?有一些开源解决方案,例如。。。您还应该能够使用InstallerSumming这是您想要分发的SASS产品,您是否考虑过创建两个docker容器,一个用于SQLite,另一个用于SQL Server?通过docker分发的?好的。因此,我认为我最大的问题是关于用户在安装过程中何时选择数据库引擎。安装程序会根据用户的选择替换my appsettings.json文件中的
UseSql
键的值吗?是的,您可以在安装项目中为此编写方法。不会有“开箱即用”的东西,您必须编写代码来创建满足特定安装程序和设置要求所需的功能,例如对appsettings.json的更改。@Dean Friedland您需要更多信息吗?对不起。刚度假回来。还有一个问题。我选择你的答案是正确的,但我会走Wix路线,除非你认为你的想法更好。您的方式比使用Wix工具集更好,有什么原因吗?我正在看这个教程。。。Wix工具集看起来是一个更好的方法!我对它不是很熟悉,但我确实找到了一篇关于微软的好文章:看看这篇文章,如果你有任何问题,请告诉我。