首先向大家道歉。我知道有很多关于这个错误的帖子。我没有找到任何与 dotNet Core 2 相关的链接。请指点我。
我创建了一个简单的 dotNet Core 2 控制台应用程序,仅使用 Main 方法。我可以将此应用程序发布为可移植的目标运行时,它会在输出文件夹中创建相关的 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/