加入收藏 | 设为首页 | 会员中心 | 我要投稿 莱芜站长网 (https://www.0634zz.com/)- 云连接、建站、智能边缘云、设备管理、大数据!
当前位置: 首页 > 编程开发 > asp.Net > 正文

.NET6打包部署到Windows Service的全过程

发布时间:2023-02-17 10:13:04 所属栏目:asp.Net 来源:互联网
导读:1.安装Nuget包 安装以下nuget包支持windows service PackageReference Include=Microsoft.AspNetCore.Hosting.WindowsServices Version=6.0.10 / PackageReference Include=Microsoft.Extensions.Hosting.WindowsServices Version=6.0.1 / 2.设置ContentRoot
  1.安装Nuget包
  安装以下nuget包支持windows service

  <PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="6.0.10" />
    <PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="6.0.1" />
 
  2.设置ContentRootPath
  不设置ContentRootPath会指向C盘sc.exe所在文件夹。

  var options = new WebApplicationOptions
  {
      Args = args,
      ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
  };
  
  var builder = WebApplication.CreateBuilder(options);
 
  3.启用WIndowsService
  通过以下方法即可启用WIndowsService支持
 
  1
  builder.Host.UseWindowsService();
 
  4.发布项目
  右键项目,进行发布,发布到文件夹
 
   5.简单安装
  通过以下BASH命令,实现安装/开始/停止/删除windows service
 
  安装

  set "CDir=%~dp0"
  sc.exe create "MyService" start=auto binpath="%CDir%MyService.exe --environment Development"
  启动
 

  sc.exe start "MyService"
  停止
 

  sc.exe stop "MyService"
  删除
 

  sc.exe delete "MyService"
 
  6.安装打包工具
  安装Inno Setup打包工具
 
  安装好后,进行汉语支持支持。打开Inno Setup安装目录,默认C:Program Files (x86)Inno Setup 6。
 
  复制Default.isl,将其拷贝至C:Program Files (x86)Inno Setup 6Languages文件夹,并重命名为Chinese.isl
 
  将以下内容覆盖到Chinese.isl

  ; *** Inno Setup version 5.5.0+ Chinese messages ***
   ;
   ; To download user-contributed translations of this file, go to:
   ;   http://www.jrsoftware.org/files/istrans/
   ;
   ; Note: When translating this text, do not add periods (.) to the end of
   ; messages that didn't have them already, because on those messages Inno
   ; Setup adds the periods automatically (appending a period would result in
   ; two periods being displayed).
    
   [LangOptions]
   ; The following three entries are very important. Be sure to read and?
   ; understand the '[LangOptions] section' topic in the help file.
   LanguageName=Chinese
   LanguageID=$0409
   LanguageCodePage=0
   ; If the language you are translating to requires special font faces or
   ; sizes, uncomment any of the following entries and change them accordingly.
   ;DialogFontName=
   ;DialogFontSize=8
   ;WelcomeFontName=Verdana
   ;WelcomeFontSize=12
   ;TitleFontName=Arial
   ;TitleFontSize=29
   ;CopyrightFontName=Arial
   ;CopyrightFontSize=8
    
   [Messages]
    
   ; *** Application titles
   SetupAppTitle=安装
   SetupWindowTitle=安装 - %1
   UninstallAppTitle=卸载
   UninstallAppFullTitle=%1 卸载
    
   ; *** Misc. common
   InformationTitle=安装信息
   ConfirmTitle=提示
   ErrorTitle=错误
    
   ; *** SetupLdr messages
   SetupLdrStartupMessage=现在将安装 %1。是否继续?
   LdrCannotCreateTemp=不能创建临时文件。安装中止!
   LdrCannotExecTemp=不能在临时目录中解压文件,安装过程中止!
    
   ; *** Startup error messages
   LastErrorMessage=%1.%n%n 错误 %2: %3
   SetupFileMissing=在安装目录中找不到文件 %1 。请更正该问题或者获得一个新的文件。
   SetupFileCorrupt=安装文件被占用。请获得一个新的安装文件。
   SetupFileCorruptOrWrongVer=安装文件被占用, 或者安装文件的版本不对。请更正该问题或者获得一个新文件。
   NotOnThisPlatform=该程序不能在 %1 下运行。
   OnlyOnThisPlatform=该程序必须在 %1 下运行。
   OnlyOnTheseArchitectures=该程序只能在以下WINDOWS版本下运行:%n%n%1
   MissingWOW64APIs=该版本需要64位的安装程序。要更正该问题,请安装 Service Pack %1。
   WinVersionTooLowError=该软件需要 %1 版本号 %2 或者更高。
   WinVersionTooHighError=该软件不能在 %1 版本号 %2 或者更高版本中安装。
   AdminPrivilegesRequired=您在安装该程序时必须是管理员权限。
   PowerUserPrivilegesRequired=您在安装程序是必须是管理员权限或者高权限用户权限。
   SetupAppRunningError=安装程序检测到 %1 正在运行。%n%n请关闭它的所有实例。然后单击“确认”继续安装,或者单击“放弃”退出。UninstallAppRunningError=卸载程序检测到 %1 正在运行。%n%n请关闭它的所有实例。然后单击“确认”继续安装,或者单击“放弃”退出。
    
   ; *** Misc. errors
   ErrorCreatingDir=安装程序不能创建目录 "%1"
   ErrorTooManyFilesInDir=不能在目录"%1" 下创建文件。因为该目录下有太多的文件了。
    
   ; *** Setup common messages
   ExitSetupTitle=退出安装
   ExitSetupMessage=安装没有完成。 如果您现在退出,程序将不被安装。%n%n您可以下次在完成安装任务。%n%n退出安装?
   AboutSetupMenuItem=关于安装程序[&A]...
   AboutSetupTitle=关于安装程序
   AboutSetupMessage=%1 版本 %2%n%3%n%n%1 主页:%n%4
   AboutSetupNote=
   TranslatorNote=
    
   ; *** Buttons
   ButtonBack=< 回退[&B]
   ButtonNext=下一步[&N] >
   ButtonInstall=安装[&I]
   ButtonOK=确认
   ButtonCancel=放弃
   ButtonYes=市[&Y]
   ButtonYesToAll=全部确认[&A]
   ButtonNo=否[&N]
   ButtonNoToAll=全部否认[&o]
   ButtonFinish=完成[&F]
   ButtonBrowse=浏览[&B]...
   ButtonWizardBrowse=浏览[&r]...
   ButtonNewFolder=新建文件夹[&M]
    
   ; *** "Select Language" dialog messages
   SelectLanguageTitle=选择安装语言种类
   SelectLanguageLabel=选择该语言作为安装语言:
    
   ; *** Common wizard text
   ClickNext=单击“下一步”继续,或者单击“放弃”退出本安装程序。
   BeveledLabel=
   BrowseDialogTitle=浏览文件夹
   BrowseDialogLabel=在下面的列表中选择一个目录, 然后单击“确认”继续。
   NewFolderName=新文件夹
    
   ; *** "Welcome" wizard page
   WelcomeLabel1=欢迎进入 [name] 安装向导
   WelcomeLabel2=将在您的电脑上安装 [name/ver] 。%n%n建议在继续安装之前退出其它程序的运行。
    
   ; *** "Password" wizard page
   WizardPassword=密码
   PasswordLabel1=本安装程序受密码保护。
   PasswordLabel3=请输入密码,密码区分大小写。然后单击“下一步”继续。
   PasswordEditLabel=密码[&P]:
   IncorrectPassword=输入的密码不正确,请重新输入。
    
   ; *** "License Agreement" wizard page
   WizardLicense=用户许可协议
   LicenseLabel=请在继续之前仔细阅读用户许可协议。
   LicenseLabel3=请仔细阅读下面的用户许可协议。在继续安装之前,您必须接受该协议。
   LicenseAccepted=我接受协议[&a]。
   LicenseNotAccepted=我不接受协议[&d]
    
   ; *** "Information" wizard pages
   WizardInfoBefore=提示
   InfoBeforeLabel=在继续安装之前请仔细阅读以下重要的信息。
   InfoBeforeClickLabel=当您准备好继续安装时,单击“继续”。
   WizardInfoAfter=信息
   InfoAfterLabel=在继续安装之前请仔细阅读以下重要的信息。
   InfoAfterClickLabel=当您准备好继续安装时,单击“继续”。

(编辑:莱芜站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读