問題
ASP.net MVC のプロジェクトで Web API を使うために System.Web.Http
をインポートしようとしたところ、Cannot resolve symbol 'Http'
と怒られてしまいました。
OS - Windows 10 pro
IDE - Rider 2018.2.3
.NetFramework - 4.6.1
解決
↓のリンクによると、nugetでインストールする必要があるそうです。
https://stackoverflow.com/questions/27819109/system-web-http-missing-after-net-4-5-upgrade
- ツールバーから
Tools > NuGet > Manage NuGet Packages for [Project Name]
を選択 - 検索バーに
Microsoft.AspNet.WebApi
を入力 - 検索結果を選択し、インストールボタンを押す
※ System.Web.Http
は Core で解決しますが、ほかの WebAPI の機能を使うには Microsoft.AspNet.WebApi
のほかのパッケージもインストールが必要です。
Microsoft.Net.Compilers のエラーが出る場合
自分の環境では、↓のようなエラーで WebAPI がインストールできませんでした。
Unable to resolve dependencies. 'Microsoft.Net.Compilers 1.3.2' is not compatible with 'Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.8 constraint: Microsoft.Net.Compilers (>= 2.4.0)'.
メッセージによると Microsoft.Net.Compiler
のバージョンが古い(要求2.4.0以上に対し1.3.2がインストールされている)とのことなので、NuGetからアップデートします。
- ツールバーから
Tools > NuGet > Manage NuGet Packages for [Project Name]
を選択 - 検索バーに
Microsoft.Net.Compilers
を入力 - 検索結果を選択し、アップデートボタンを押す
- アップデートが終わったら再度
Micorosft.AspNet.WebApi.Core
を検索してインストール