iT邦幫忙

2021 iThome 鐵人賽

DAY 20
0
Software Development

@30天 | C# WixToolset + WPF 帥到不行的安裝包系列 第 20

@Day20 | C# WixToolset + WPF 帥到不行的安裝包 [Bootstrapper-安裝前的系統檢測]

基本上

在學習時看的文章,
都會在這邊放了個安裝檢測.net framework的方法
https://www.cnblogs.com/stoneniqiu/p/3380805.html

那我不免俗一起來一段安裝前檢測用法,
只是因為我們HelloWorld專案是用.Net Core的方式 !

而官方文件只有到4.6.2….

哈!好險我有找到使用 core 3.1 的使用方式
https://github.com/wixtoolset/issues/issues/6099


我們先加入參考檔案WixUtilExtension.dll

在Wix標籤的參考加入

xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"

然後Bundle標籤下面找個地方貼上

  <Fragment>
    <Variable Name="AspNetCoreRuntime31InstallDir" Value="[ProgramFiles64Folder]dotnet\shared\Microsoft.AspNetCore.App\3.1.0" />
    <util:DirectorySearch Id="AspNetCoreRuntime31Installed" Path="[AspNetCoreRuntime31InstallDir]" Variable="AspNetCoreRuntime31Installed" Result="exists" />

    <WixVariable Id="AspNetCoreRuntime31WebDetectCondition" Value="AspNetCoreRuntime31Installed" Overridable="yes" />
    <WixVariable Id="AspNetCoreRuntime31WebInstallCondition" Value="" Overridable="yes" />

    <PackageGroup Id="AspNetCoreRuntime31Web">
      <ExePackage
          Name="aspnetcore-runtime-3.1.0-win-x64.exe"
          InstallCommand="/install /quiet /norestart /log "[AspNetCoreRuntime31Log]""
          RepairCommand="/repair /quiet /norestart /log "[AspNetCoreRuntime31Log]""
          UninstallCommand="/uninstall /quiet /norestart /log "[AspNetCoreRuntime31Log]""
          PerMachine="yes"
          DetectCondition="!(wix.AspNetCoreRuntime31WebDetectCondition)"
          InstallCondition="!(wix.AspNetCoreRuntime31WebInstallCondition)"
          Vital="yes"
          Permanent="yes"
          Protocol="burn"
          DownloadUrl="https://download.visualstudio.microsoft.com/download/pr/a16689d1-0872-4ef9-a592-406d3038d8f7/cf4f84504385a599f0cb6a5c113ccb34/aspnetcore-runtime-3.1.0-win-x64.exe"
          LogPathVariable="AspNetCoreRuntime31Log"
          Compressed="no">
        <!-- heat.exe payload "aspnetcore-runtime-3.1.0-win-x64.exe" -o "aspnetcore-runtime.wxs" -->
        <RemotePayload
          CertificatePublicKey="6608A9DBA86701156A4C17CE63BA99BE8B932F8D"
          CertificateThumbprint="62009AAABDAE749FD47D19150958329BF6FF4B34"
          Description="Microsoft ASP.NET Core 3.1.0 - Shared Framework"
          Hash="2DFD4F9EA2E174A7199C40ED3A826886F1E19EF8"
          ProductName="Microsoft ASP.NET Core 3.1.0 - Shared Framework"
          Size="7811768"
          Version="3.1.0.19566" />
      </ExePackage>
    </PackageGroup>
  </Fragment>

  <Fragment>
    <Variable Name="WindowsDesktopRuntime31InstallDir" Value="[ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App\3.1.0" />
    <util:DirectorySearch Id="WindowsDesktopRuntime31Installed" Path="[WindowsDesktopRuntime31InstallDir]" Variable="WindowsDesktopRuntime31Installed" Result="exists" />

    <WixVariable Id="WindowsDesktopRuntime31WebDetectCondition" Value="WindowsDesktopRuntime31Installed" Overridable="yes" />
    <WixVariable Id="WindowsDesktopRuntime31WebInstallCondition" Value="" Overridable="yes" />

    <PackageGroup Id="WindowsDesktopRuntime31Web">
      <ExePackage
          Name="windowsdesktop-runtime-3.1.0-win-x64.exe"
          InstallCommand="/install /quiet /norestart /log "[WindowsDesktopRuntime31Log]""
          RepairCommand="/repair /quiet /norestart /log "[WindowsDesktopRuntime31Log]""
          UninstallCommand="/uninstall /quiet /norestart /log "[WindowsDesktopRuntime31Log]""
          PerMachine="yes"
          DetectCondition="!(wix.WindowsDesktopRuntime31WebDetectCondition)"
          InstallCondition="!(wix.WindowsDesktopRuntime31WebInstallCondition)"
          Vital="yes"
          Permanent="yes"
          Protocol="burn"
          DownloadUrl="https://download.visualstudio.microsoft.com/download/pr/a1510e74-b31a-4434-b8a0-8074ff31fb3f/b7de8ecba4a14d8312551cfdc745dea1/windowsdesktop-runtime-3.1.0-win-x64.exe"
          LogPathVariable="WindowsDesktopRuntime31Log"
          Compressed="no">
        <!-- heat.exe payload "windowsdesktop-runtime-3.1.0-win-x64.exe" -o "windowsdesktop-runtime.wxs" -->
        <RemotePayload
          CertificatePublicKey="6608A9DBA86701156A4C17CE63BA99BE8B932F8D"
          CertificateThumbprint="62009AAABDAE749FD47D19150958329BF6FF4B34"
          Description="Microsoft Windows Desktop Runtime - 3.1.0 (x64)"
          Hash="C16F271754879BA78868947486F37871C9F0E40F"
          ProductName="Microsoft Windows Desktop Runtime - 3.1.0 (x64)"
          Size="54443856"
          Version="3.1.0.28315" />
      </ExePackage>
    </PackageGroup>
  </Fragment>

範例給了兩個抓Runtime部分的,我們只要用一個就可以了

  • AspNetCoreRuntime31Web
  • WindowsDesktopRuntime31Web

在Chain標籤內在我們主體安裝包前 貼上他的寫法

而他主要用的方法是去查看Microsoft.AspNetCore.App下有沒有建立這個3.1.0的資料夾

 <Variable Name="AspNetCoreRuntime31InstallDir" Value="[ProgramFiles64Folder]dotnet\shared\Microsoft.AspNetCore.App\3.1.0" />

我們建置後執行看看!↓↓↓

水唷! 可以看到打包檔就會先檢測有沒有Runtime,沒有了話會直接安裝Runtime3.1.0後,
才執行接下來主要的安裝包部分。

那因為這個是由網路下載的,
如果說有些公司有內外網分離的情況,
我們只好使用預先手動下載的方式,

先下載aspnetcore-runtime-3.1.0-win-x64.exe後放在程式內,
SourceFile指定位置↓↓↓

    <PackageGroup Id="AspNetCoreRuntime31Web">
      <ExePackage
          Name="aspnetcore-runtime-3.1.0-win-x64.exe"
          InstallCommand="/install /quiet /norestart /log "[AspNetCoreRuntime31Log]""
          RepairCommand="/repair /quiet /norestart /log "[AspNetCoreRuntime31Log]""
          UninstallCommand="/uninstall /quiet /norestart /log "[AspNetCoreRuntime31Log]""
          PerMachine="yes"
          DetectCondition="!(wix.AspNetCoreRuntime31WebDetectCondition)"
          InstallCondition="!(wix.AspNetCoreRuntime31WebInstallCondition)"
          Vital="yes"
          Permanent="yes"
          Protocol="burn"
          SourceFile="aspnetcore-runtime-3.1.0-win-x64.exe"
          LogPathVariable="AspNetCoreRuntime31Log"
          Compressed="yes">
      </ExePackage>
    </PackageGroup>

如果檔案想要附加在我們的Bootstrapper.exe
那Compressed 要改為 yes ,這樣檔案就會附加進去,
若沒有想要附加就維持 no,然後檔案屬性部分改成一律複製
最後移除掉整串RemotePayload 因為這個是由網址下載的情況才需要的。

建置後執行看看吧!



  • 後記

我在這邊有測試過Runtime安裝,
基本上server 2019 2016 安裝上是沒問題,2012 必須升級到R2 才可以進行安裝,

然後像是我們的專案 CustomAction.dll,Framework是4.6.2的版本,
測試時我也有一併測試,
但exe檔包出來的安裝包,
基本上就不用擔心他有沒有Framework的問題,
所以就把檢測拔掉了XD

Day20程式碼
https://github.com/Aslan7826/defaultMVC/commits/Day20


上一篇
@Day19 | C# WixToolset + WPF 帥到不行的安裝包 [Bootstrapper-基礎介紹]
下一篇
@Day21 | C# WixToolset + WPF 帥到不行的安裝包 [Log在哪邊查詢]
系列文
@30天 | C# WixToolset + WPF 帥到不行的安裝包30

尚未有邦友留言

立即登入留言