はじめに
ずっと「Visual Studio for Mac」を使っていたのですが、2024年8月にサポートが終了してしまうとのことなので少し早いですが「Visual Studio Code」に作業環境を移行した話です。少しつまづいたので残しておきます。
Microsoft は、Visual Studio for Mac の提供終了を発表しました。 Visual Studio for Mac は、2024 年 8 月 31 日でサポートが終了します。 代替手段は次のとおりです。
・C# 開発キットおよび関連する拡張機能 (.NET MAUI、Unity など) を含む Visual Studio Code。
・Mac 上の VM の Windows 上で実行されている Visual Studio。
・クラウド内の VM の Windows 上で実行されている Visual Studio。

久しぶりに「External Script Editor」を変更
挙動の軽さに惹かれて2年くらい前に「Visual Studio Code」をメインに使おうと移行を試みたことがあったのですが、インテリセンスや定義元ジャンプなどが効かなくなったりして不安定だったので諦めたことがあります。
以前と比べて今はどうなのか? 久しぶりにUnityの「External Script Editor」を「Visual Studio Code」へ変更しました。
- Visual Studio Code 1.84.1
- Unity 2022.3.10
- Visual Studio Editor package 2.0.22

プラグインのインストールとレガシーパッケージ削除
「Visual Studio Code」起動するとUnity用のプラグインをおすすめされたのでインストール
Unity -Integrates Visual Studio Code with Unity

「Visual Studio Code Editor package」はレガシー扱いになったようなのでUnityエディター側で削除。 逆に「Visual Studio Editor package」は最新版へ更新。

そしてエラー
……定義元ジャンプ「F12」が効かない。参照元検索「Shift+F12」も効かない。これじゃあまともに使えないTT
よく見ると「出力(C#)」に下記のエラーが表示されていました。
Failed to find dotnet info from path, falling back to acquire runtime via ms-dotnettools.vscode-dotnet-runtime
Error running dotnet –info: Error: Command failed: dotnet –info
/bin/sh: dotnet: command not found
Dotnet path: /Users/***/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.13~x64/dotnet
Activating C# + C# Dev Kit + C# IntelliCode…
先ほど入れたプラグイン「Unity-Integrates Visual Studio Code with Unity」の必要条件にも「.NET7」が記載されていました。
Requirements
・Unity 2019 LTS or greater.
・Activated C# Dev Kit extension in Visual Studio Code.
・.NET 7 SDK or greater, the C# Dev Kit will install it if required.
・Visual Studio Editor Unity package 2.0.20 or greater.
どうやらPCに入っている「dotnet」が古いようなので、最新版「.NET7.0」をインストール。

ついでに、古い「dotnet」もお掃除。

ここまでやって「Visual Studio Code」を起動してみたところ定義元ジャンプができるようになりました!
<追記> ところが……
Unityを再起動したり違うプロジェクトを開いたりすると、上記と同じ「Failed to find dotnet info from path」エラーが発生。
その場合は「Visual Studio Code」を再起動するかPCを再起動すると直ります。(なんか環境パスが不安定^^;)
おわりに
少しつまづきましたが無事「Visual Studio Code」をメインに使う準備ができました。ショートカットは覚え直しですが「Visual Studio for Mac」に比べて挙動が軽いのは良いですね。早く慣れたいと思います。
参考

