C# WIX: регистрация моего приложения ASP.NET CORE в качестве службы Windows с установщиком WIXC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 C# WIX: регистрация моего приложения ASP.NET CORE в качестве службы Windows с установщиком WIX

Сообщение Anonymous »

Я пытаюсь заставить мой установщик Wix зарегистрировать мое приложение ASP.net Core в качестве службы Windows во время установки.
Это часть моей программы. /p>











Но во время установки я получаю эту ошибку:
< /p>
Конечно, он спрашивает меня во время установки для администратора. И я нажимаю «запустить как администратор», но это не помогает. < /p>
Есть идеи о том, что может быть неправильно? Program.cs :
var builder = WebApplication.CreateBuilder(args);
int freePort = 0;

// Load default settings
builder.Configuration
.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables();

builder.Host.UseWindowsService(options =>
{
options.ServiceName = "Nav.LocalService"; // MUST MATCH WiX ServiceInstall Name
});

// Determine user-specific settings file path in AppData
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var userSettingsFilePath = Path.Combine(appDataPath, "LocalService", "local.settings.json");

if (File.Exists(userSettingsFilePath))
{
// if we have a local file for each user, take this instead and leave the other one as backup
builder.Configuration.AddJsonFile(userSettingsFilePath, optional: true, reloadOnChange: true);
}
else
{
// copy local file if it doenst already exist

// Ensure the directory exists
var directoryPath = Path.GetDirectoryName(userSettingsFilePath);
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
var sourceFilePath = Path.Combine(Directory.GetCurrentDirectory(), "local.settings.json");

var fileContent = File.ReadAllText(sourceFilePath); // Read the content of the existing file

File.WriteAllText(userSettingsFilePath, fileContent);

builder.Configuration.AddJsonFile(userSettingsFilePath, optional: true, reloadOnChange: true);

Thread.Sleep(100);
}

var getLastUsedPort = builder.Configuration["Values:Application:FunctionAppPort"];

builder.Services
.AddHttpClient()
.AddTransient()
.AddTransient()
.AddTransient()
.AddTransient()
.AddSingleton()
.AddTransient()
.AddSingleton()
.AddHostedService()
.AddHostedService()
.AddControllers();

var app = builder.Build();

if (String.IsNullOrEmpty(getLastUsedPort))
{
// no old port available get a new one
freePort = Converters.GetFreePort();
var updater = new ConfigUpdater();
updater.UpdateConfig("Application:FunctionAppPort", freePort.ToString());
}
else
{
// we had a port already, check if its free
var portStillFree = Converters.IsPortAvailable(int.Parse(getLastUsedPort));

if (!portStillFree)
{
// port is no longer free, retrieve new one, write to config and update on BC
freePort = Converters.GetFreePort();
var updater = new ConfigUpdater();
updater.UpdateConfig("Application:FunctionAppPort", freePort.ToString());

//Update new port on BC
using (var scope = app.Services.CreateScope())
{
var ntlmRegisterSender = scope.ServiceProvider.GetRequiredService();
await ntlmRegisterSender.UpdateFieldValue("Port", freePort.ToString());
}
}
else
{
// do nothing, leave everythign as it is
}
}

var logger = app.Services.GetRequiredService();

// Hide the console window
HideConsoleWindow();

app.UseRouting();
app.MapControllers();

Thread.Sleep(1000);

string uripath = builder.Configuration["Values:Application:FunctionAppUrl"] ?? "http://localhost:";

uripath += builder.Configuration["Values:Application:FunctionAppPort"] ?? "7072";

string trayAppPath = Converters.GetPathToWPFApp(builder.Configuration["TrayAppPath"]);

try
{
Process.Start(trayAppPath, uripath);
logger.LogInformation("Successfully started the tray app.");
}
catch (Exception ex)
{
logger.LogWarning(ex, "Could not start the tray app. Check local.settings.json for the correct path.");
}

try
{
app.Run(uripath);
}
catch (Exception ex)
{
Console.WriteLine($"Failed to start server: {ex.Message}");
}

void HideConsoleWindow()
{
IntPtr handle = GetConsoleWindow();

if (handle != IntPtr.Zero)
{
ShowWindow(handle, 0);
}
}

[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);


Подробнее здесь: https://stackoverflow.com/questions/794 ... -wix-insta
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»