首先,向所有人道歉。我知道有关于此错误的多篇帖子。我没有找到任何与dotNet Core 2相关的链接。请指出他们。
我用Main方法创建了一个简单的dotNet Core 2控制台应用程序。我能够将此应用程序发布为可移植目标运行时,它在输出文件夹中创建相关的DLL文件。
成功创建服务后,该服务无法在本地计算机上启动并抛出提及的错误&#34;错误1053:服务未及时响应启动或控制请求&#34; < / p>
dotnet ConsoleApplicationService.dll
&#34;从命令提示符,然后应用程序按预期运行。 我确保从已发布的文件夹中打开命令提示符并运行以下代码:
sc create&#34; myDev控制台服务&#34; binpath =&#34; C:\ inetpub \ wwwroot \ myDev.ConsoleApplicationService \ ConsoleApplicationService.dll&#34;
这是我的环境:
Microsoft Windows 8.1 Enterprise Visual Studio Professional 2017
版本15.5.7 Microsoft .Net Framework版本4.7.02558
Program.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>
答案 0 :(得分:0)
确保您的服务已启用允许服务与桌面交互选项。 要启用此选项,请按以下步骤操作:
答案 1 :(得分:0)
我设法找到了一种方法来完成这项工作并开始我的服务。我遵循了Peter Kottas创建的微服务架构库,如果您的控制台应用程序是dotNet Core 2中的代码,那么这绝对是您的选择。
请参阅GitHub上的链接:https://github.com/PeterKottas/DotNetCore.WindowsService