我发现了一个有趣的案例,但我无法完全理解。
我的运行时 - PowerShell 7.2.4
我有两个 PowerShell Core 模块:Net6PowerShellModule和NetstandardPowerShellModule。
Net6PowerShellModule.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<None Remove="Net6PowerShellModule.psd1" />
</ItemGroup>
<ItemGroup>
<Content Include="Net6PowerShellModule.psd1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Management.Automation" Version="7.2.4" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
测试-Net6Cmdlet.cs
using System.Management.Automation;
namespace Net6PowerShellModule
{
[Cmdlet("Test", "Net6Cmdlet")]
public class TestNet6Cmdlet : PSCmdlet
{
protected override void ProcessRecord()
{
var type = typeof(Microsoft.Extensions.DependencyInjection.IServiceCollection);
WriteObject("Net6 Cmdlet Run.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
Net6PowerShellModule.psd1
@{
RootModule = 'Net6PowerShellModule.dll'
ModuleVersion = '0.0.1' …Run Code Online (Sandbox Code Playgroud) 我写了一个Windows Service在Win10上运行,在我决定对其进行一些更改之前,它运行得很好。我重写了一些逻辑,在Debug和Release配置中对其进行了测试,一切都很好。然后,我使用卸载了当前版本的服务installutil.exe /u %servicename.exe%,然后使用重新安装了该版本installutil.exe %servicename.exe%。由于某种原因,该新版本无法启动,并且因错误1064崩溃。这是完整的错误文本:
Windows could not start %servicename% service on Local Computer. Error 1064: An exception occurred in the service when handling the control request.
上次安装此服务时,遇到了一些困难,但是通过更改Log On属性很快解决了这些问题。这次,它不起作用。请帮助解决此问题。
谢谢。
更新1
这是我Main()和OnStart()服务方法:
Main()
static void Main()
{
#if DEBUG
var service = new SalesforceToJiraService();
service.OnDebug();
Thread.Sleep(Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new SalesforceToJiraService()
};
ServiceBase.Run(ServicesToRun);
#endif
}
Run Code Online (Sandbox Code Playgroud)
OnStart()
protected override void OnStart(string[] args)
{
this.ConfigureServices();
this.timer.Start();
this.logger.Information("SalesforceToJira …Run Code Online (Sandbox Code Playgroud)