VS2022 template "ASP.NET Core Worker Service template" missing

EuroEager2008 171 Reputation points
2023-05-19T09:36:38.71+00:00

The article
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?source=recommendations&view=aspnetcore-7.0&tabs=visual-studio
mentions a template named "ASP.NET Core Worker Service template".

I assume this is ment to be a template accesible by VS2022, but I cannot find it.
What am I doing wrong?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,389 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,874 questions
{count} votes

Accepted answer
  1. Jerry Fu - MSFT 571 Reputation points Microsoft Vendor
    2023-05-19T12:27:05.77+00:00

    Hi @EuroEager2008 ,

    I didn't find a template to run worker service in asp.net core app/API project officially. But there are some clues to do this. Although the article uses Ihost to build service project. You can still register the service class directly to asp.net core project which host by webapplicationbuilder like below.

    builder.Services.AddHostedService<TimedHostedService>();
    builder.Services.AddHostedService<Worker>();
    
    

    (Note that the 'worker' is copy from the default worker service template," TimedHostedService" is the code from https://learn.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?source=recommendations&view=aspnetcore-7.0&tabs=visual-studio#timed-background-tasks ).

    They will work the same as in a Ihostbuilder project.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful