首先向大家道歉。我知道有多个关于此错误的帖子。我没有找到与 dotNet Core 2 相关的任何链接。请指出它们。
我仅使用 Main 方法创建了一个简单的 dotNet Core 2 控制台应用程序。我能够将此应用程序发布为可移植目标运行时,它在输出文件夹中创建相关的 DLL 文件。
成功创建服务后,服务无法在我的本地机器上启动并抛出“错误 1053:服务没有及时响应启动或控制请求”的错误
- 我确保我构建并发布为“发布”。
- 我确保当我从命令提示符运行“
dotnet ConsoleApplicationService.dll
”时,应用程序会按预期运行。 我确保从发布的文件夹打开命令提示符并运行以下代码:
sc create "myDev Console Service"binpath= "C:\inetpub\wwwroot\myDev.ConsoleApplicationService\ConsoleApplicationService.dll"
这是我的环境:
Microsoft Windows 8.1 Enterprise Visual Studio Professional 2017
Version 15.5.7 Microsoft .Net Framework Version 4.7.02558
程序.cs
class Program
{
static void Main(string[] args)
{
var fileName = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "log.txt");
File.AppendAllText(fileName, "Hello, I am starting" + "\n");
Console.WriteLine(" _____________________________________________________________________________");
Console.WriteLine("| Test Console Application as a Service |");
Console.WriteLine("|-----------------------------------------------------------------------------|");
Console.WriteLine("| Version : 1.0.0 |");
Console.WriteLine("| Created by : S. Govindsamy |");
Console.WriteLine("| Created on : 20 Mar 2018 |");
Console.WriteLine("| Last updated : |");
Console.WriteLine("|_____________________________________________________________________________|");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine($"dotNet Version: {Environment.Version}");
Console.WriteLine(DateTime.Now.ToString("dd MMM yyyy HH:mm:ss") + "..Started");
Console.WriteLine("Checking to see if this is working ... press any key to exit...");
File.AppendAllText(fileName, "Hello, I have written text to console ..." + "\n");
Console.ReadLine();
File.AppendAllText(fileName, "Hello, I am ending now ..." + "\n");
}
}
ConsoleApplication.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win7-x64;win8-x64;win81-x64;win10-x64;osx-x64</RuntimeIdentifiers>
<StartupObject>ConsoleApplicationService.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
<PackageReference Include="ServiceProcess.Helpers" Version="0.9.1.9" />
</ItemGroup>
</Project>
最佳答案
确保您的服务已打开允许服务与桌面交互选项。 要打开此选项,请按照下列步骤操作:
- 在“服务”工具中,单击要启动的服务,然后单击属性。
- 右键单击登录选项卡,然后单击以选中允许服务与桌面交互复选框。
- 单击确定退出属性对话框。
关于windows-services - dotNet Core 2 控制台应用程序 - 错误 1053 : The service did not respond in a timely fashion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49453572/