BackgroundService를 사용하여 Windows 서비스 만들기 - .NET | Microsoft Learn
새 프로젝트 만들기 작업자 서비스
cmd 열어서 입력
dotnet add package Microsoft.Extensions.Hosting.WindowsServices
프로젝트명.csproj 파일 열어 보면 추가 되어 있습니다.
<Project Sdk="Microsoft.NET.Sdk.Worker">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-Mik.SmartPortal.MqLogProcessing.Service.Core-d6abff3d-2332-4188-bdc5-7698f28ffa97</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.0" />
</ItemGroup>
</Project>
* 클래스를 추가 합니다.
콘솔애플리케이션으로 생성
플랫폼은 WIN x64로 생성
<OutputType>exe</OutputType>
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PlatformTarget>x64</PlatformTarget>
예제 class를 작성하고
sc create "Service.Core" binpath="C:\ApvSource\Service.Core\bin\Release\net8.0\win-x64\publish\Service.Core.exe"
댓글 영역