创建 asp.net web api 核心 2.0 项目的 msi
Create msi of asp.net web api core 2.0 project
我正在创建一个 ASP.net 核心 2.0 WEB API 项目,需要在使用 MSI 设置的系统上作为 Windows 服务部署。有什么办法可以做到吗?
我已经尝试过的事情:
时间紧迫,只是一些链接,看看它是否能让你继续:
- Various Deployment Tools(快速 运行 用于创建 MSI 的部署工具)
- WiX Quick Start Suggestions(奇怪的是这个答案似乎对人们有所帮助)
- A very quick overview of MSI (also see the top links to installsite.org's 运行设置工具下载)
本质上:
- 您需要下载并安装 WiX 工具包 到 运行 WiX。
- 如果您想使用 Visual Studio 中的 WiX 源文件,您还应该获得 Visual Studio 扩展 (除了主 WiX 下载).
- 从这里下载两者:http://wixtoolset.org/releases/
我喜欢将 WiX 安装主目录中的 bin
文件夹添加到 Path 环境变量中,以便能够调用 WiX 构建工具 - candle.exe
、light.exe
、etc...
- 来自任何地方。
您也可以在 Visual Studio 之外编译 WiX 源文件。最简单的形式:
set SetupName=MySetup
candle.exe %SetupName%.wxs >> %SetupName%.log
light.exe -out %SetupName%.msi %SetupName%.wixobj >> %SetupName%.log
或者,没有线路噪音:
candle.exe Setup.wxs
light.exe -out Setup.msi Setup.wixobj
类似问题:
- Visual Studio 2017 C# installer project is not installing my app
我通过使用 Wix 创建一个 msi 解决了这个问题。我看了 this Video 并按照它的指示操作。
为了创建 windows 服务,我使用了 NSSM,我复制了 nssm.exe 作为安装程序的一部分。
使用了以下命令:
nssm 安装服务名称
为了自动创建服务,我使用了 WiX 的 CustomAction。
要为 .Net core 2 创建 MSI…首先像
一样发布你的项目
dotnet publish --configuration Release --runtime win7-x64 --self-contained false --output c:\outputfolder
您可以通过添加
使其成为您的 .wixproj 的一部分
<Target Name="BeforeBuild">
<PropertyGroup>
<BasePath>$(SolutionDir)\publish\bin$(Configuration)\FilesToPackage</BasePath>
</PropertyGroup>
<!-- Clean previous build folder -->
<Exec Command="rd /s /q $(BasePath)" />
<!-- Publish dotnet core app -->
<Exec Command="dotnet publish $(MSBuildThisFileDirectory)\..\..\src\yourproject.csproj -r win-x64 --self-contained false --output $(BasePath)" />
<!-- Get assembly version -->
<GetAssemblyIdentity AssemblyFiles="$(BasePath)\yourproject.dll">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<!-- Define some variables we need -->
<PropertyGroup>
<DefineConstants>ProductVersion=%(AssemblyVersion.Version);BasePath=$(BasePath)</DefineConstants>
</PropertyGroup>
<HeatDirectory
OutputFile="YourServiceComponent.wxs"
DirectoryRefId="INSTALLFOLDER"
ComponentGroupName="yourproject_component"
SuppressCom="true" Directory="$(BasePath)"
SuppressFragments="true"
SuppressRegistry="true"
SuppressRootDirectory="true"
AutoGenerateGuids="false"
GenerateGuidsNow="true"
ToolPath="$(WixToolPath)"
PreprocessorVariable="var.BasePath"
Transforms="RemoveFiles.xslt"
/>
</Target>
Heat 将使用输出中的所有文件创建 wxs 文件,但您需要删除 yourservice.exe,因此将该信息添加到 RemoveFiles.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="pdb-search" match="wix:Component[contains(wix:File/@Source, '.pdb')]" use="@Id" />
<xsl:template match="wix:Component[key('pdb-search', @Id)]" />
<xsl:template match="wix:ComponentRef[key('pdb-search', @Id)]" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/@Source, 'Your.Service.exe')]" use="@Id"/>
<xsl:template match="wix:Component[key('service-search', @Id)]"/>
<xsl:template match="wix:ComponentRef[key('service-search', @Id)]"/>
</xsl:stylesheet>
最后,您希望 Wix 向 Windows 服务控制管理器 (SCM) 注册您的服务,因此将以下内容添加到您的 Product.wxs
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<ComponentGroupRef Id="yourproject_component" />
<Component Id="ServiceAssemblyComponent" Guid="{GUID}">
<File Id="ServiceAssembly" Source="$(var.BasePath)\Your.Service.exe" KeyPath="yes" />
<ServiceInstall Id="ServiceInstallation" DisplayName="$(var.ProductName)" Name="$(var.ProductName)" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" />
<ServiceControl Id="ServiceControl" Name="$(var.ProductName)" Stop="both" Remove="uninstall" />
</Component>
</ComponentGroup>
</Fragment>
我正在创建一个 ASP.net 核心 2.0 WEB API 项目,需要在使用 MSI 设置的系统上作为 Windows 服务部署。有什么办法可以做到吗?
我已经尝试过的事情:
时间紧迫,只是一些链接,看看它是否能让你继续:
- Various Deployment Tools(快速 运行 用于创建 MSI 的部署工具)
- WiX Quick Start Suggestions(奇怪的是这个答案似乎对人们有所帮助)
- A very quick overview of MSI (also see the top links to installsite.org's 运行设置工具下载)
本质上:
- 您需要下载并安装 WiX 工具包 到 运行 WiX。
- 如果您想使用 Visual Studio 中的 WiX 源文件,您还应该获得 Visual Studio 扩展 (除了主 WiX 下载).
- 从这里下载两者:http://wixtoolset.org/releases/
我喜欢将 WiX 安装主目录中的 bin
文件夹添加到 Path 环境变量中,以便能够调用 WiX 构建工具 - candle.exe
、light.exe
、etc...
- 来自任何地方。
您也可以在 Visual Studio 之外编译 WiX 源文件。最简单的形式:
set SetupName=MySetup
candle.exe %SetupName%.wxs >> %SetupName%.log
light.exe -out %SetupName%.msi %SetupName%.wixobj >> %SetupName%.log
或者,没有线路噪音:
candle.exe Setup.wxs
light.exe -out Setup.msi Setup.wixobj
类似问题:
- Visual Studio 2017 C# installer project is not installing my app
我通过使用 Wix 创建一个 msi 解决了这个问题。我看了 this Video 并按照它的指示操作。
为了创建 windows 服务,我使用了 NSSM,我复制了 nssm.exe 作为安装程序的一部分。 使用了以下命令: nssm 安装服务名称
为了自动创建服务,我使用了 WiX 的 CustomAction。
要为 .Net core 2 创建 MSI…首先像
一样发布你的项目dotnet publish --configuration Release --runtime win7-x64 --self-contained false --output c:\outputfolder
您可以通过添加
使其成为您的 .wixproj 的一部分 <Target Name="BeforeBuild">
<PropertyGroup>
<BasePath>$(SolutionDir)\publish\bin$(Configuration)\FilesToPackage</BasePath>
</PropertyGroup>
<!-- Clean previous build folder -->
<Exec Command="rd /s /q $(BasePath)" />
<!-- Publish dotnet core app -->
<Exec Command="dotnet publish $(MSBuildThisFileDirectory)\..\..\src\yourproject.csproj -r win-x64 --self-contained false --output $(BasePath)" />
<!-- Get assembly version -->
<GetAssemblyIdentity AssemblyFiles="$(BasePath)\yourproject.dll">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<!-- Define some variables we need -->
<PropertyGroup>
<DefineConstants>ProductVersion=%(AssemblyVersion.Version);BasePath=$(BasePath)</DefineConstants>
</PropertyGroup>
<HeatDirectory
OutputFile="YourServiceComponent.wxs"
DirectoryRefId="INSTALLFOLDER"
ComponentGroupName="yourproject_component"
SuppressCom="true" Directory="$(BasePath)"
SuppressFragments="true"
SuppressRegistry="true"
SuppressRootDirectory="true"
AutoGenerateGuids="false"
GenerateGuidsNow="true"
ToolPath="$(WixToolPath)"
PreprocessorVariable="var.BasePath"
Transforms="RemoveFiles.xslt"
/>
</Target>
Heat 将使用输出中的所有文件创建 wxs 文件,但您需要删除 yourservice.exe,因此将该信息添加到 RemoveFiles.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="pdb-search" match="wix:Component[contains(wix:File/@Source, '.pdb')]" use="@Id" />
<xsl:template match="wix:Component[key('pdb-search', @Id)]" />
<xsl:template match="wix:ComponentRef[key('pdb-search', @Id)]" />
<xsl:key name="service-search" match="wix:Component[contains(wix:File/@Source, 'Your.Service.exe')]" use="@Id"/>
<xsl:template match="wix:Component[key('service-search', @Id)]"/>
<xsl:template match="wix:ComponentRef[key('service-search', @Id)]"/>
</xsl:stylesheet>
最后,您希望 Wix 向 Windows 服务控制管理器 (SCM) 注册您的服务,因此将以下内容添加到您的 Product.wxs
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<ComponentGroupRef Id="yourproject_component" />
<Component Id="ServiceAssemblyComponent" Guid="{GUID}">
<File Id="ServiceAssembly" Source="$(var.BasePath)\Your.Service.exe" KeyPath="yes" />
<ServiceInstall Id="ServiceInstallation" DisplayName="$(var.ProductName)" Name="$(var.ProductName)" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" />
<ServiceControl Id="ServiceControl" Name="$(var.ProductName)" Stop="both" Remove="uninstall" />
</Component>
</ComponentGroup>
</Fragment>