Ich versuche, mein Wix -Installationsprogramm meine ASP.NET -Core -App als Windows.msc -Dienst während der Installation zu haben.
Dies ist Teil meines Programms.
Aber während der Installation erhalte ich diesen Fehler:
< /p>
fragt mich natürlich während der Installation für Admin Prev. Und ich klicke auf "als Administrator ausführen", aber das scheint nicht zu helfen. CS: < /p>
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);
Ich versuche, mein Wix -Installationsprogramm meine ASP.NET -Core -App als Windows.msc -Dienst während der Installation zu haben. Dies ist Teil meines Programms. [code]
[/code] Aber während der Installation erhalte ich diesen Fehler: < /p> fragt mich natürlich während der Installation für Admin Prev. Und ich klicke auf "als Administrator ausführen", aber das scheint nicht zu helfen. CS: < /p> [code]var builder = WebApplication.CreateBuilder(args); int freePort = 0;
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
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 } }
Ich erstelle ein ASP.NET Core MVC-Projekt mit Identitätskonten und als ich auf die Schaltfläche „Registrieren“ klicke (auf der Registrierungsseite).
Ich habe diese Ausnahme erhalten:
Während der...
Ich hatte das Problem, meine Dienste zu registrieren. Ich brauchte einen Mechanismus, den die App automatisch alle meine Dienste basierend auf Marker -Schnittstellen findet und registrieren würde....
Ich versuche, Python auf einem Computer mit Windows 8.1 x64 zu installieren, und jedes Mal, wenn ich es ausprobiert habe, installiert der Installationsprogramm Pip. (alle x64), und beim letzten Mal...
Ich arbeite mit Nopcommerce und muss meinen einzigen Aktionsfilter hinzufügen. Ich möchte jedoch nicht die Kerncontroller ändern, um zu vermeiden, dass mein Code überschrieben wird, wenn ein neues...
Ich weiß, dass dies schon oft gefragt wurde, aber leider nicht über ASP.NET -Web -Apps, nur die klassischen ASP.NET -Web -Apps. Alle Antworten, die ich im Internet gefunden habe, helfen mir nicht, da...