flamencist / flamencist/Core.System.Configuration.Install

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

Đang mở
#8 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C#
Star
26
Fork
12
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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?

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu với ManagedInstallerClass.InstallHelper và thiết lập ServiceInstaller được nêu trong issue, sau đó tái hiện việc cài đặt .NET 6 bằng Assembly.GetExecutingAssembly().Location và Environment.ProcessPath. Theo dõi cách thư viện suy ra đường dẫn tệp nhị phân của dịch vụ và xác minh bản sửa lỗi bằng cách cài đặt thành công, với dịch vụ được cấu hình để khởi chạy tệp thực thi dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp
Lĩnh vực
operating-systems, tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.