c++ - 如何在我的安装程序中包含 .NET Core(Windows 和 macOS)
问题描述
我有一个依赖 .NET Core 与 C# 程序集交互的 C++ 应用程序。我希望我的应用程序无需先安装其他组件即可工作,因此我想在我的安装程序中包含 .NET Core。
Microsoft 提供了一些脚本,但它们适用于 CI(它们执行非管理员安装)。使用脚本安装后,该load_hostfxr
功能(请参阅本教程)无法找到安装。
然后,我如何提供 .NET Core 的完整安装?该功能如何在load_hostfxr
内部检查是否dotnet
已安装(在 Mac 和 Win 中)?
注意:我在 Windows 安装程序中使用 Wix,在 macOS 安装程序中使用“Packages”应用程序。
解决方案
我终于通过使用微软提供的安装程序解决了这个问题。
苹果系统
将 .NET Core pkg 作为“资源”包含在 Packages 项目中,然后创建一个安装后脚本来执行它:
#!/bin/sh
sudo installer -pkg dotnet-runtime-3.1.10-osx-x64.pkg -target /
在这种情况下,将静默安装 .NET Core。
视窗
使用 Burn,我创建了一个新的 Bootstrapper 项目。生成的 .exe 将执行我以前的安装程序 (.msi) 以及 .NET Core 安装程序。
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<?include ..\Setup_Custom\Variables.wxi ?>
<Bundle Name="!(loc.ProductName) $(var.VersionNumber)" Version="$(var.VersionNumber)" Manufacturer="!(loc.ManufacturerName)" UpgradeCode="$(var.UpgradeCode)" IconSourceFile="Icon.ico">
<BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense"/>
<WixVariable Id="WixStdbaLicenseRtf" Value="License.rtf" />
<WixVariable Id="WixStdbaLogo" Value="Logo.png" />
<Chain>
<PackageGroupRef Id="dotnet3"/>
<MsiPackage
Compressed="yes"
SourceFile="CustomSetup.msi"
Vital="yes"/>
</Chain>
</Bundle>
<Fragment>
<util:DirectorySearch
Id="NetCoreInstalled"
Variable="NetCoreInstalled"
Path="[ProgramFiles64Folder]dotnet\shared\Microsoft.NETCore.App\3.1.10"
Result="exists" />
<PackageGroup Id="dotnet3">
<ExePackage
Id="dotnet3"
InstallCondition="NOT NetCoreInstalled"
DetectCondition="NetCoreInstalled"
Cache="no"
Compressed="yes"
PerMachine="yes"
Permanent="yes"
Vital="yes"
SourceFile="dotnet-runtime-3.1.10-win-x64.exe"
DownloadUrl="https://download.visualstudio.microsoft.com/download/pr/9845b4b0-fb52-48b6-83cf-4c431558c29b/41025de7a76639eeff102410e7015214/dotnet-runtime-3.1.10-win-x64.exe"/>
</PackageGroup>
</Fragment>
</Wix>
在这种情况下,将显示 .NET Core 安装程序 UI。
推荐阅读
- dart - Why the value of the variable is not changed out the method
- visual-studio - How do I deploy to a new Remote Machine?
- javascript - How to strip the dollar sign from an array and keep only numbers? js
- angular-material2 - Angular Material2 Mat-Table Server Side Pagination Cross Page Row Selection
- perl - use of perl @ARGV
- node.js - Terraform 创建了 AWS ECS 基础设施:运行状况检查一直失败
- amazon-web-services - AWS Security group requirements for user data
- sonarqube - SonarQube Azure Devops Not Authorized
- python - How to return a value from a function to another function with Tkinter?
- java - 发布请求中的 Android volley Body