使用 msbuild 时,当前上下文中不存在 DependencyResolver

sen*_*ale 1 c# msbuild asp.net-mvc dependency-injection asp.net-mvc-4

我正在使用 ASP.NET MVC 4 依赖注入,比如

DependencyResolver.Current.GetService<IUserContext>();
Run Code Online (Sandbox Code Playgroud)

这在 Visual Studio 中运行良好,但是当我使用 msbuild 构建项目时,我总是遇到此异常:

BaseClasses\EntityRepositoryBase.cs (68,40): errorCS0103: The name 'DependencyResolver' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)

我能做什么?我再次安装了 mvc4 但还是一样。

Bal*_*ala 5

我认为文件中缺少 DependencyResolver 的命名空间,请将以下内容添加到命名空间列表中

using System.Web.Mvc;