LoginSignup
3
1

EmacsにOmnisharpをinstallする際嵌まったお話

Last updated at Posted at 2024-03-26

はじめに

名古屋でWEB系エンジニアをやっている片田です

ある日、Emacsにomnisharpをインストールしようとしたら嵌まったのでシェアしようと思います

TL;DR

Omnisharpをインストールできない問題

  • lsp-install-serverからはインストールできなかった
  • Omnisharpを手動でインストールすることにて解決

Omnisharpが動かない問題

  • 原因はlibhostfxr.dylibが読み込めていなかった
  • 環境変数DOTNET_ROOTに.NET Coreのパスを設定することで解決

環境

  • M2 Mac(Sonoma 14.12.1)
  • .NET Core 8.0.3 (asdfでインストール)
  • Emacs GNU 28.2

Omnisharpをインストールできない

LSP :: Download omnisharp started.
LSP :: Starting to download https://github.com/omnisharp/omnisharp-roslyn/releases/latest/download/omnisharp-osx-arm64-net6.0.zip to /Users/s-katada/.emacs.d/.cache/lsp/omnisharp-roslyn/latest/omnisharp-roslyn.zip.zip...
Contacting host: github.com:443
Saving file /Users/s-katada/.emacs.d/url/cookies...
Wrote /Users/s-katada/.emacs.d/url/cookies
LSP :: Server omnisharp install process failed with the following error message: (file-missing Opening URL No such file or directory https://github.com/omnisharp/omnisharp-roslyn/releases/latest/download/omnisharp-osx-arm64-net6.0.zip).
Check `*lsp-install*' and `*lsp-log*' buffer.

lsp-install-server関数でomnisharpをインストールできませんでした
ChatGPTやClaude3にお尋ねしたところ、ネットワークが悪いと言われたが特に問題はありませんでした

直接インストールしてみる

cd ~/.emacs.d/.cache/lsp/omnisharp-roslyn/latest
curl -OL https://github.com/OmniSharp/omnisharp-roslyn/releases/download/v1.39.1/omnisharp-osx-arm64-net6.0.zip && unzip omnisharp-osx-arm64-net6.0.zip

正常にインストールができました!

Omnisharpが動作しない...

M-x RET lsp
LSP :: Connected to [omnisharp:59684/starting /Users/s-katada/git/private/dotnet_todo_app][semgrep-ls:59685/starting /Users/s-katada/git/private/dotnet_todo_app].
LSP :: omnisharp has exited (exited abnormally with code 131)
LSP :: semgrep-ls:59685 initialized successfully in folders: (/Users/s-katada/git/private/dotnet_todo_app)
Server omnisharp:59684/starting exited (check corresponding stderr buffer for details). Do you want to restart it? (y or n) y
LSP :: Restarting LSP in buffer Program.cs
LSP :: Connected to [omnisharp:60043/starting /Users/s-katada/git/private/dotnet_todo_app][semgrep-ls:59685 /Users/s-katada/git/private/dotnet_todo_app].
LSP :: omnisharp has exited (exited abnormally with code 131)

インストールはできましたが動作しないです...なぜがExitしてしまいます...
*lsp-logを確認したがどこでエラーが起きているかわかりませんでした

シェルから直接動かしてみる

直接Omnisharpを動かして確認してみます。

cd ~/.emacs.d/.cache/lsp/omnisharp-roslyn/latest
./Omnisharp.dll

するとエラー内容を確認できました!

./Omnisharp
A fatal error occurred. The required library libhostfxr.dylib could not be found.
If this is a self-contained application, that library should exist in [/Users/s-katada/.dotfiles/.emacs.d/.cache/lsp/omnisharp-roslyn/latest/].
If this is a framework-dependent application, install the runtime in the global location [/usr/local/share/dotnet/x64] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [/etc/dotnet/install_location].

The .NET runtime can be found at:
  - https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=arm64&rid=osx.11.3-arm64&apphost_version=6.0.0-preview.7.21317.1

Omnisharpが.NET Coreのバイナリ場所を理解してなさそうです
片田はasdfで.NET Coreをインストールしているので、/usr/local/share/dotnet/x64に.NET Coreは存在しません

解決策

環境変数DOTNET_ROOTに.NET Coreのバイナリパスを渡すことで解決できました!

片田の場合

export DOTNET_ROOT="/Users/s-katada/.asdf/installs/dotnet-core/8.0.203"

動作確認

無事動作しました!

image.png

まとめ

  • lsp-install-serverからインストールはできなかったが、手動でインストールして動作させることができました

  • brewで.NET Coreをインストールしていればこの問題は起きなかったかもしれないです(バージョンを管理できないので嫌)

ベストプラクティスではないと思いますが、参考になれば幸いです!

3
1
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
3
1