2021年02月13日

[Unity] Visual Studio CodeでC#のメソッド一覧が表示されない(No editor symbols)ときの対処法

Visual Studio Code(以降、VSC)の便利な機能に、メソッドや変数一覧を表示する機能があります。

環境:
Unity 2020.2.2f1
MacOS Catalina 10.15.7

Macなので、VSCの画面にて、[command] + [Shift] + [o] を押すと画面上に「@」と入力された状態の入力蘭が表示され、メソッド等の一覧が表示されます。
しかし、そうはなりませんでした。

スクリーンショット 2021-02-12_1.png

エディタには何やら警告が表示されているので、「Show Output」を押してログを確認してみました。

スクリーンショット 2021-02-12_2.png



[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '/Users/Shared/Unity/AppName/Assembly-CSharp.csproj'.
/Users/Shared/Unity/AppName/Assembly-CSharp.csproj
/Users/hogehoge/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.6/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1180,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
[fail]: OmniSharp.MSBuild.ProjectManager
Attempted to update project that is not loaded: /Users/Shared/Unity/AppName/Assembly-CSharp.csproj



どうもC#用のパックが必要らしいので、記載されているURLに行ってみるものの、Winしかありませんでした。
困ったので調べてみると、以下の方法で解決できました。

■Unity側
@Player Settings > Other Settings > Configuration > Api Compatibility Level を「.NET 4.x」に変更。
■mac側
@homebrewを最新版にアップデート
※homebrew = macのPackageManagerのようなもの
Ahomebrewからmonoをインストール
BVSCの設定ファイルに追記

具体的に説明していきます。



■Unity側
@Player Settings > Other Settings > Configuration > Api Compatibility Level を「.NET 4.x」に変更。

.NETの設定が合っていない可能性があるので、プロジェクト設定を「.Net Standard 2.0」から「.Net 4.x」に変更。

スクリーンショット 2021-02-13_6.png

次に、Package Managerから、VSCに関するものを最新版に上げてみました。

スクリーンショット 2021-02-12_3.png

この段階で解決しなかったので、次はmac側の環境設定を調べてみたところ、homebrewが古くて設定も完了していないようでした。



■mac側
@homebrewを最新版にアップデート

最新版にアップデートしようとしたところ、エラーが出てしまいました。


% brew update
fatal: could not read Username for 'https://github.com': terminal prompts disabled
Error: homebrew/homebrew-php does not exist! Run `brew untap homebrew/homebrew-php` to remove it.
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3_2.yosemite.bottle.tar.gz
################################################################# 100.0%
==> Pouring portable-ruby-2.6.3_2.yosemite.bottle.tar.gz


ログで指定されたコマンドをそのまま打ちます。


% brew untap homebrew/homebrew-php
Untapping homebrew/php...
Untapped (35 files, 829.2KB).


再びアップデートを試みるも、再びエラー。


% brew update
Error:
homebrew-core is a shallow clone.
To `brew update`, first run:
git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
This command may take a few minutes to run due to the large size of the repository.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!


指定されたコマンドを打ったところ、今度は無事アップデートできました。


% git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
remote: Enumerating objects: 428535, done.
remote: Counting objects: 100% (428498/428498), done.
remote: Compressing objects: 100% (164714/164714), done.
remote: Total 420389 (delta 257766), reused 415481 (delta 252864), pack-reused 0
Receiving objects: 100% (420389/420389), 149.84 MiB | 15.91 MiB/s, done.
Resolving deltas: 100% (257766/257766), completed with 3776 local objects.


念のため確認。


% brew update
Already up-to-date.


次は、homebrewの設定状況を確認するため、「doctor」コマンドを使います。


% brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: The following directories do not exist:
/usr/local/Frameworks

You should create these directories and change their ownership to your user.
sudo mkdir -p /usr/local/Frameworks
sudo chown -R $(whoami) /usr/local/Frameworks

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
/usr/local/lib/libTMAESCrypt.a

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
boost
php
mysql

Warning: Xcode alone is not sufficient on Catalina.
Install the Command Line Tools:
xcode-select --install

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
/usr/local/bin/innochecksum
 ……(たくさん)

Warning: Homebrew's "sbin" was not found in your PATH but you have installed
formulae that put executables in /usr/local/sbin.
Consider setting your PATH for example like so:
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc


doctorで指摘されたコマンドを全て実行。


% sudo mkdir -p /usr/local/Frameworks
% sudo chown -R $(whoami) /usr/local/Frameworks
% brew cleanup
% xcode-select --install
% brew link boost
% brew link php
% brew link mysql
% rm -rf /usr/local/lib/libTMAESCrypt.a
% echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc


パスの設定変更を反映。


% source ~/.zshrc


これでhomebrewの設定が完了しました。念のため確認。


% brew doctor
Your system is ready to brew.


次のステップへ。

Ahomebrewからmonoをインストール

monoがインストールされているかと思いきや、インストールされていませんでした。


% brew upgrade mono
Updating Homebrew...
Error: mono not installed


なので、monoをインストール。


% brew install mono


数分でインストールできたので、doctorコマンドで設定をチェック。


% brew doctor
Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
mono

Warning: Broken symlinks were found. Remove them with `brew cleanup`:
/usr/local/bin/easy_install-3.8
/usr/local/bin/pip3.8


指定されたコマンドを打ち、monoにリンクを貼りました。


% brew cleanup
% brew link mono
% brew doctor
Your system is ready to brew.


最後に、VSCの設定ファイルを編集します。

BVSCの設定ファイルに追記

まずは、インストールされたmonoのバージョンを確認。


% cd /usr/local/Cellar/mono
% ls
6.12.0.107


このバージョン番号を使い、VSCの設定ファイルに追記します。

スクリーンショット 2021-02-13_4.png

macの場合、パスは
/Users/[ユーザー名]/Library/Application Support/Code/User/settings.json
でした。

赤い部分が追記した箇所です。


{
"window.zoomLevel": 0,
"omnisharp.useGlobalMono": "always",
"omnisharp.monoPath": "/usr/local/Cellar/mono/6.12.0.107"

}


VSCを再起動して、[command] + [Shift] + [o]を押してみたところ、無事、メソッド一覧が表示されました。

スクリーンショット 2021-02-13_5.png

これで作業効率が上がる!!

参考:
https://qiita.com/kyasbal_1994/items/ecf19a3feb60a12a61f9
https://qiita.com/hajimeni/items/b8d1b5db1cb08eeb7d1d
https://qiita.com/Ytz_Ichi/items/94e1c5c45fc8fd4459fa
https://qiita.com/ponsuke0531/items/f2ea798bcc8f1e876d90
https://qiita.com/haruu_11113/items/0bdde67f17b60e4fb657
https://qiita.com/FrogWoman/items/7c0fdaa7550dc5895a33
posted by be-style at 21:17| Comment(0) | Unity
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント: [必須入力]

※ブログオーナーが承認したコメントのみ表示されます。