.Net Core 2.0 Windows Service

前端 未结 10 1354
谎友^
谎友^ 2021-01-30 01:25

I\'m trying to build a Windows Service in .Net Core 2.0 but I\'ve been banging my head on the wall for a full day and no progress at all. Everything seems to be using Core 1.0/1

10条回答
  •  情歌与酒
    2021-01-30 02:12

    To host .NET Core 2.0 Web API as Windows Service. I followed this guide Host ASP.NET Core in a Windows Service. The Prerequisites part is unclear to me. After some mistakes, here is what I did: Source Code

    1. Create an ASP.NET Core Web Application
    2. Choose API
    3. Edit .csproj file, need to change target framework from netcoreapp2.0 to net461, explicitly list all the package references rather than using Microsoft.AspNetCore.All, as following

    
    
      
        net461
        win7-x64
        
      
    
      
        
      
    
      
        
        
        
        
        
        
        
      
    
      
        
      
    
    

    1. power shell [solution-folder] dotnet publish -o "[publish-folder]"
    2. power shell [solution-folder] sc.exe create CoreApi binpath="[publish-folder]\CoreApiHostedAsWindowsService.exe"
    3. power shell [solution-folder] sc.exe start CoreApi
    4. visit default api power shell [solution-folder] Invoke-WebRequest http://localhost:5000/api/values

提交回复
热议问题