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
のほかのパッケージもインストールが必要です。
自分の環境では、↓のようなエラーで 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 を検索してインストール