azukipochette's weblog

memory dump (mini)

とにかく最新の .NET SDK (Preview) を使いたい

今日の出来事

とある事情で .NET SDK 7.0.2 SDK に実装されたらしい機能を試す必要があった。
そして、先日の 2023 年 1 月 10 日に待望の "7.0.2" がリリースされたと聞き、颯爽と .NET 7.0 ダウンロード サイトを開いた! ...が、そこには .NET 7.0.2 SDK は無かった。(ランタイムは 7.0.2 なのに)

最新インストーラーの確認と公式 Docker イメージ

.NET SDK Installers のリポジトリを見てみると、最新のプレビュー バージョンは 7.0.200-preview.23062.11 らしい。

github.com

これが欲しいが、自分のローカルマシンに直接インストールするのはリスクが大きいので、サンドボックス化したい。 サッと思いつくのは、DockerHub に公開されている NET SDK のイメージ。

hub.docker.com

上記のアドレスは正式公開版が置かれているが、欲しいのは開発中の Preview 版なので "nightly" を見に行く。

hub.docker.com

Full Tag Listing の記載を見ると、残念ながら本日時点で 7.0 を指し示すと 7.0.102 が指定されるとある。
どうやら nightly ではあるものの 7.0.200 ではないようだ。というわけで、公式ビルドを使うのは諦め。

インストール スクリプト

一時的に動きを確認できれば事足りるので、Windows Sandbox に入れることにした。 インストールするためのスクリプトはここにある。

github.com

今回は Windows Sandbox なので PowerShellスクリプトを落とし、下記のように実行する。

.\dotnet-install.ps1 -Channel 7.0.2xx -Quality daily

これで 7.0.2 系の最新のビルド(日次ビルドの成果物)をダウンロード&インストールしてくれる。

おまけ

実際にインストールした際のログを下記に示す。

PS C:\works> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
PS C:\works> .\dotnet-install.ps1 -Channel 7.0.2xx -Quality daily
dotnet-install: Note that the intended use of this script is for Continuous Integration (CI) scenarios, where:
dotnet-install: - The SDK needs to be installed without user interaction and without admin rights.
dotnet-install: - The SDK installation doesn't need to persist across multiple CI runs.
dotnet-install: To set up a development environment or to run apps, use installers rather than this script. Visit https://dotnet.microsoft.com/download to get the installer.

dotnet-install: Extracting the archive.
dotnet-install: Adding to current process PATH: "C:\Users\WDAGUtilityAccount\AppData\Local\Microsoft\dotnet\". Note: This change will not be visible if PowerShell was run as a child process.
dotnet-install: Note that the script does not resolve dependencies during installation.
dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install/windows#dependencies
dotnet-install: Installed version is 7.0.200-preview.23062.11
dotnet-install: Installation finished
PS C:\works> dotnet --version
7.0.200-preview.23062.11

メッセージを読むと環境変数ではなく、現在のプロセスにパスを追加しており、インストール先も %LOCALAPPDATA% 配下になっていることがわかる。 他のプロセスなどで dotnet CLI を使う場合などは注意すると良いだろう。