无法在TeamCity中构建.Net MVC项目

时间:2014-11-27 00:05:23

标签: asp.net asp.net-mvc teamcity

我正在尝试在TeamCity中为.Net MVC项目设置构建。我按照此处描述的步骤进行了操作:How to build ASPNET applications in TeamCity

但构建仍然失败。我的错误信息是

App_Start\BundleConfig.cs(2, 18): error CS0234: The type or namespace name 'Optimization' does 

not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
App_Start\FilterConfig.cs(2, 18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
App_Start\RouteConfig.cs(5, 18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
Controllers\HomeController.cs(5, 18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
Controllers\HomeController.cs(9, 35): error CS0246: The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?) 
Global.asax.cs(5, 18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
Global.asax.cs(6, 18): error CS0234: The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) 
App_Start\BundleConfig.cs(9, 44): error CS0246: The type or namespace name 'BundleCollection' could not be found (are you missing a using directive or an assembly reference?) 
App_Start\FilterConfig.cs(8, 50): error CS0246: The type or namespace name 'GlobalFilterCollection' could not be found (are you missing a using directive or an assembly reference?) 
Controllers\HomeController.cs(11, 16): error CS0246: The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?) 
Controllers\HomeController.cs(16, 16): error CS0246: The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?) 
Controllers\HomeController.cs(23, 16): error CS0246: The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?) 

我在csproj中拥有Copy Local = true和True的所有引用。 TeamCity正在正确下载nuget包,但似乎没有使用它们。我只能看到obj / Release中的.csprojResolveAssemblyReference文件中有以下行:

C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.5.1 \ System.Web.dll

所以,似乎是使用该文件而不是nuget文件夹中的文件。

我需要做些什么才能进行构建和运行?

非常感谢。

3 个答案:

答案 0 :(得分:3)

您需要在构建过程中添加一个步骤来恢复所有NuGet包。 有关说明,请参阅here

答案 1 :(得分:1)

System.Web.Optimization命名空间不在System.Web.dll程序集中。它有自己的程序集System.Web.Optimization.dll。添加该DLL作为参考。如果您没有该DLL,请通过NuGet获取。我认为this是正确的包。

答案 2 :(得分:0)

我终于解决了这个问题。我所做的是将NuGet包上传到源代码存储库并删除TeamCity配置中的NuGet步骤。实际上,我更喜欢这个选项能够在我的代码中工作,尽管NuGet失败了。

非常感谢。