flamencist / flamencist/Core.System.Configuration.Install

Service is being created with executable path pointing to DLL instead of EXE

未關閉
#8 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C#
星號
26
分支
12
PR 合併指標
30 天內沒有已合併 PR

描述

We have a service installation code which works just fine with .NET Frameworks 4.8 Console application based on `ServiceBase`:

```C#
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
```

```C#
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;

namespace TestServiceInstall
{
[RunInstaller(true)]
public class TestServiceInstaller : Installer
{
public TestServiceInstaller()
{
ServiceProcessInstaller processInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();

// set the privileges
processInstaller.Account = ServiceAccount.LocalSystem;

serviceInstaller.DisplayName = GlobalVar.SERVICE_NAME;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.DelayedAutoStart = true;
serviceInstaller.ServicesDependedOn = new string[] { "Tcpip" };

// must be the same as what was set in Program's constructor
serviceInstaller.ServiceName = GlobalVar.SERVICE_NAME;

// installer code here
this.AfterInstall += new InstallEventHandler(ServiceInstaller_AfterInstall);

this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
}

void ServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
ServiceController sc = new ServiceController(GlobalVar.SERVICE_NAME);
sc.Start();
}
}
}
```

We tried to migrate to .NET 6.0 and use this library to install the service in a same way we used to, but what happens is service binary path changed from EXE file to DLL file and we can't figure out how to point it to the EXE file.

We've tried changing `Assembly.GetExecutingAssembly().Location` to `Environment.ProcessPath` but it gives us the following error:

```
System.BadImageFormatException: Bad IL format. The format of the file '%EXE path here%' is invalid..
```

So the question is how can we use this library to install a windows service pointing to EXE file instead of DLL?

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

從 ManagedInstallerClass.InstallHelper 和 issue 中所示的 ServiceInstaller 設定開始,接著使用 Assembly.GetExecutingAssembly().Location 和 Environment.ProcessPath 重現 .NET 6 安裝流程。追蹤程式庫如何推導服務二進位檔路徑,並透過成功安裝服務來驗證修正,同時將服務設定為啟動預期的可執行檔。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
csharp
領域
operating-systems, tooling
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。