[英]c# Windows Service does not work when publish with installutil.exe
我有一个类型为 Windows 服务的 .net 框架 4.6.1 应用程序,当我在本地运行应用程序时它可以工作。 我使用以下命令在 windows 中发布:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe" "C:\Bitworks\Git\pbxbitworks\PBX.WindowsService\bin\Release\PBX.WindowsService.exe"
该命令失败,异常类型为System.InvalidOperationException: Cannot get installer types in assembly 。 使用 Fusion Log 时,我可以观察到以下内容
*** Assembly Linkers Log Entry (5/20/2021 @ 6:06:46 PM) ***
Operation failed.
Link result: hr = 0x80070002. The system cannot find the specified file.
The assembly manager was loaded from: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
Execution under executable file C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe
--- Detailed error log.
=== Status information before link ===
LOG: DisplayName = System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic base = NULL
LOG: Cache Base = NULL
LOG: AppName = InstallUtil.exe
Call assembly: PBX.WindowsService, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null.
===
LOG: This link starts in the load context LoadFrom.
AVS: The native image will not be parsed in the LoadFrom context. It will only be parsed in a default loading context, such as with Assembly.Load ().
LOG: Using the application configuration file: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe.Config
LOG: Using the host configuration file:
LOG: Using the computer configuration file in C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ machine.config.
LOG: Post-directive reference: System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
LOG: GAC search unsuccessful.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http/System.Web.Http.DLL.
LOG: Attempt to download new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http.EXE.
LOG: Attempt to download new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.WindowsService/bin/Release/System.Web.Http/System.Web.Http.EXE.
LOG: All URLs were tried unsuccessfully.
*** Assembly Linkers Log Entry (5/20/2021 @ 6:06:46 PM) ***
Operation failed.
Link result: hr = 0x80070002. The system cannot find the specified file.
The assembly manager was loaded from: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
Execution under executable file C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe
--- Detailed error log.
=== Status information before link ===
LOG: DisplayName = System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic base = NULL
LOG: Cache Base = NULL
LOG: AppName = InstallUtil.exe
Call assembly: PBX.WindowsService, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null.
===
LOG: This link starts in the load context LoadFrom.
AVS: The native image will not be parsed in the LoadFrom context. It will only be parsed in a default loading context, such as with Assembly.Load ().
LOG: Using the application configuration file: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe.Config
LOG: Using the host configuration file:
LOG: Using the computer configuration file in C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ machine.config.
LOG: Post-directive reference: System.Web.Http, Version = 5.2.7.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35
LOG: GAC search unsuccessful.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.DLL.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/System.Web.Http/System.Web.Http.EXE.
LOG: Attempt to download the new URL file: /// C: /Bitworks/Git/pbxbitworks/PBX.Win
*** Assembly linkers log entry (5/20/2021 @ 12:37:55) ***
Operation failed.
Link result: hr = 0x80070002. The system cannot find the specified file.
The assembly manager was loaded from: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ clr.dll
Execution under executable file C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe
--- Detailed error log.
=== Status information before link ===
LOG: DisplayName = InstallUtil.resources, Version = 4.0.0.0, Culture = en-ES, PublicKeyToken = b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic base = NULL
LOG: Cache Base = NULL
LOG: AppName = InstallUtil.exe
Call assembly: InstallUtil, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a.
===
LOG: This link starts in the default load context.
LOG: Using the application configuration file: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ InstallUtil.exe.Config
LOG: Using the host configuration file:
LOG: Using the computer configuration file in C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ config \ machine.config.
LOG: Post-directive reference: InstallUtil.resources, Version = 4.0.0.0, Culture = en-ES, PublicKeyToken = b03f5f7f11d50a3a
LOG: The same link was already detected, which generated an error hr = 0x80070002.
ERR: Unrecoverable error during pre-download check (hr = 0x80070002).
My application has an OWIN Self-Host API and I use swagger on that API with Swashbuckle.Core 5.6.0 package and I also have Microsoft.AspNet.WebApi.Core 5.2.7 package installed.
有趣的是,在卸载 Swashbuckle.Core 时,安装 windows 服务是成功的。 谁能指导我如何使这两个包存在于同一个项目中而不会发生冲突?
对于我的项目,需要使用 Swagger,据我了解,在您自己的自托管 api 中使用 swagger 的方法是使用 Swashbuckle.Core。
更新:
installutil 是唯一一个在创建 windows 服务时给我带来 dll 问题的命令,该命令
sc create ServiceName binPath="fullservicepath.exe"
它对我有用,直到我找到 installutil 解决方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.