Skip to main content
 首页 » 编程设计

c#之尝试在窗口服务中托管 .NET Core 2.1 Web 应用程序会创建 dll 而不是 exe

2024年02月04日29sharpest

按照说明操作 here我:

  • 已安装 visual studio 2017 预览版
  • 已安装 .NET Core 2.1 RC1
  • dotnet 添加包 Microsoft.AspNetCore.Hosting.WindowsServices --version 2.1.0-rc1-final

新项目->
选择左侧的 .NET Core ->
选择 ASP.NET Core Web 应用程序 ->
在顶部选择 ASP.NET Core 2.1 ->
选择 Web 应用程序 ->
在 program.cs 添加 using Microsoft.AspNetCore.Hosting.WindowsServices; ->
在 program.cs 中将 Run() 更改为 RunAsService() ->
构建发布 ->
在 cmd 中执行 dotnet publish

我得到:

>dotnet publish 
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Core 
Copyright (C) Microsoft Corporation. All rights reserved. 
 
  Restoring packages for C:\Temp\VoyDashServer\VoyDashServer\VoyDashServer\VoyDashServer.csproj... 
  Generating MSBuild file C:\Temp\VoyDashServer\VoyDashServer\VoyDashServer\obj\VoyDashServer.csproj.nuget.g.props. 
  Restore completed in 1.56 sec for C:\Temp\VoyDashServer\VoyDashServer\VoyDashServer\VoyDashServer.csproj. 
  You are working with a preview version of the .NET Core SDK. You can define the SDK version via a global.json file in the current project. More at https://go.microsoft.com/fwlink/?linkid=869452 
  VoyDashServer -> C:\Temp\VoyDashServer\VoyDashServer\VoyDashServer\bin\Debug\netcoreapp2.1\VoyDashServer.dll 
  VoyDashServer -> C:\Temp\VoyDashServer\VoyDashServer\VoyDashServer\bin\Debug\netcoreapp2.1\VoyDashServer.Views.dll 
  VoyDashServer -> C:\Temp\VoyDashServer\VoyDashServer\VoyDashServer\bin\Debug\netcoreapp2.1\publish\ 

也就是说结果是dll而不是exe

我做错了什么?

请您参考如下方法:

在最后一步,代替 dotnet publish 做

dotnet publish -c Release --self-contained -r win-x64 

这将生成 .exe