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

4

我正在尝试在TeamCity中为一个.Net MVC项目设置构建。我按照这里描述的步骤进行了操作:如何在TeamCity中构建ASPNET应用程序

但是构建仍然失败了。我收到的错误信息如下:

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文件夹中的文件。
为使构建成功,我需要做些什么呢?
非常感谢。

我有完全相同的问题,但是使用的是TFS而不是TeamCity,所以我很想看看可能的解决方案是什么。 - Brendan Green
3个回答

3

您需要在构建过程中添加一个步骤来还原所有NuGet包。 请参阅此处的说明。


1

System.Web.Optimization 命名空间不在 System.Web.dll 程序集中。它有自己的程序集,叫做 System.Web.Optimization.dll。将该 DLL 添加为引用。如果没有这个 DLL,请通过 NuGet 获取。我认为 this 是正确的包。


我已经通过NuGet引用了System.Web.Mvc和System.Web.Optimization,而TeamCity正在下载这两个包。我不明白为什么它不在packages文件夹中查找它们。 - vgaltes
尝试手动将DLL文件复制到bin文件夹中。我之前曾经自动复制失败过。 - mason
没成功。我想重新安装机器然后再试一次。 - vgaltes

0

我终于解决了这个问题。我的做法是将 NuGet 包上传到源代码仓库并在 TeamCity 配置中移除 NuGet 步骤。实际上,即使 NuGet 崩溃,我也更喜欢这个选项,因为它能让我在我的代码中工作。

非常感谢您。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接