LoginSignup
1
0

More than 1 year has passed since last update.

.NET 6アプリを4系統にダウングレードした

Posted at

作業背景

Visual Studio 2022環境で作成された.NET 6アプリをダウングレードする案件が発生した。

以下がVisual Studioでの追加パッケージ・コンポーネント。

■NuGet
・Microsoft.Web.WebView2 最新の安定版

■Comオブジェクト
・Microsoft ActiveX Data Objects 6.1 Library
・Microsoft Excel 16.0 Object Library

手元の環境はVisual Studio 2017で、以下内容は作業メモです。

VS2017環境で.NET 6アプリをビルドできるか

.NET SDK 6.0がVisual Studio 2017に対応していない事からターゲットフレームワーク設定に含めるには不可である事が分かった。
https://learn.microsoft.com/ja-jp/dotnet/core/install/windows?tabs=net60

VS2019だとプレビュー機能をONして手動で設定ファイルを弄れば
.NET 6アプリが少し作れるようだがサポートされていない状況。

.NET 6移行に少し詳しくなれたが、Visual Studio 2017でのビルド不可である事が分かった。

https://redwarrior.hateblo.jp/entry/2021/10/12/090000
https://learn.microsoft.com/en-us/answers/questions/620284/how-to-target-net-60-with-visual-studio-2019.html
https://let.blog.jp/article/28910593
https://nishy-software.com/ja/dev-sw/visual-studio-2019-net-6/
https://hackmd.io/@jkofK/SylYeZGxY
https://devlog.grapecity.co.jp/migration-dotnet-framework-to-dotnet-6/
https://www.slideshare.net/microsoftjp/bs4-net-6

アプリのダウングレードを試みた

アプリ自体は.NET6機能を使っていない。WebView2は.NET 4.5以降をサポートしている。
https://learn.microsoft.com/ja-jp/microsoft-edge/webview2/
Visual Studio 2017のNuGetでWebView2がインストール済なので.NET 4.72をターゲット設定してインストーラを作成した。

6系統から4系統にダウングレードする際にプロジェクトファイルを編集してVisual Basic ランタイムライブラリへの参照を使用するようにした。
https://learn.microsoft.com/ja-jp/dotnet/visual-basic/misc/bc30456

下記サイトを参考にインストーラー作成を行った。
https://knkomko.hatenablog.com/entry/2019/09/15/033608
https://blog.goo.ne.jp/yoossh/e/4e45cf315efcbe035c07f9eac3fd2377
https://www.osadasoft.com/visual-studio-2017%E3%81%A7%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%A9%E4%BD%9C%E6%88%90/

インストール時にスタートアップ設定も追加。
https://sys-guard.com/post-14669/

必須コンポーネントにNET Framework オフライン インストーラも追加。
https://knkomko.hatenablog.com/entry/2020/05/17/032638

Microsoft.Web.WebView2もオフラインインストーラに追加するが、カスタムブートストラップパッケージを自作する必要がある。設定を自作した。
https://learn.microsoft.com/ja-jp/visualstudio/deployment/creating-bootstrapper-packages?view=vs-2022

ビルド時にいくつか警告が発生するので下記を参考に対処した。
https://social.msdn.microsoft.com/Forums/aspnet/ja-JP/c08f5f9f-a61a-47f0-9dec-13a6d8e37a90/net-framework-472?forum=visualstudiosupportteamja
http://bbs.wankuma.com/index.cgi?mode=al2&namber=87326&KLOG=150
https://aimek-developer.blogspot.com/2017/06/vc-vc6.html
http://blog.livedoor.jp/soudensan/archives/7585171.html
https://www.ipentec.com/document/visual-studio-2015-installer-project-error-not-compatible-with-the-project-s-target

NuGetでWebView2のモジュールを入れ直したところ参照エラーが発生した。
packagesファルダのファイルを全て削除したところエラーは解消された。
https://itblogdsi.blog.fc2.com/blog-entry-429.html

ビルド時のターゲットフレームワーク設定でMicrosoft.Web.WebView2.Core.dllは不要なのでパッケージから除外した。
またARM64のWebView2Loader.dllも不要なので除外した。

下記サイトを参考にカスタムビルドの設定をした。
https://technote.space/programming/vs-installer-merge/
https://qiita.com/Kosen-amai/items/44392fdf3bd8b56cfacb

下記サイトを参考にインストーラーのカスタム動作設定を実装した。
とりあえずIDとパスワードをexeに引き渡しiniに保存される動きとなった。
https://dobon.net/vb/dotnet/deployment/customaction.html
https://dobon.net/vb/dotnet/process/shell.html
https://social.msdn.microsoft.com/Forums/ja-JP/f23c81cc-6962-483d-a323-f6036e93322f/vs200512398124751248312488124501248312503125031252512472124551246

iexpressではディレクトリ(フォルダ)の指定は不可だった。
https://www.grot3.com/memo/iexpress/iexpress.html
フォルダ付きインストーラーを作る(msi、exe、必須コンポーネントをまとめる)ために、cmdとvbsを自作した。
カスタマイズを入れたのでPost-build Event Command Lineの設定は止めた。
http://blog.livedoor.jp/blackwingcat/archives/1100048.html

その他、細かい設定を行った。
Microsoft Visual Studio 2017 Installer Projects で すべてのユーザー/このユーザーのみ の選択肢を非表示にする
https://kameyatakefumi.hatenablog.com/entry/2018/08/15/133014

RemovePreviousVersionsプロパティをTrueにする
https://dobon.net/vb/dotnet/deployment/upgrades.html

インストーラーでProgram Files 以外のフォルダをデフォルトにする。
https://teratail.com/questions/348564
https://blog.yuizi.com/2012/04/program-files.html

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0