asp.net-mvc - 如何让 MSBuild 使用被引用为 nuget 包的 MVC 程序集来构建我的解决方案

标签 asp.net-mvc asp.net-mvc-4 visual-studio-2012 nuget

我正在尝试获得一个 MVC 解决方案以在测试服务器上构建,而无需在机器上安装 visual studio 或 MVC 4。

该解决方案将所有必需的 MVC 程序集称为 nuget 包。在项目中,所有 MVC 程序集都标记为复制本地。当然,在我的开发机器上,解决方案在 visual studio 中构建得很好。

在构建机器上,我安装了 .net sdk,我正在尝试使用 MSBuild 来构建解决方案。所有 nuget 包都在源代码控制下,当我在服务器上执行 SVN 更新时,它会获取所有包。

当我运行构建时,我得到了一个损坏的 MVC DLL 引用。我不明白为什么会发生这种情况,因为在解决方案中引用了 DLL 并存在以供构建使用。

这是 MSBuild 返回的错误示例...

DataAnnotations\RunDataAnnotationsFromModelPropertyAttribute.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?)
DataAnnotations\RunDataAnnotationsFromModelPropertyAttribute.cs(12,93): error CS0246: The type or namespace name 'IClientValidatable' could not be found (are you missing a using directive or an assembly reference?)
Security\MyAuthenticateAttribute.cs(6,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
Security\MyAuthenticateAttribute.cs(12,48): error CS0246: The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)
Security\MyAuthorizeAttribute.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?)
Security\MyAuthorizeAttribute.cs(13,45): error CS0246: The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)
Web\Mvc\MyLoginController.cs(7,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
Web\Mvc\MyLoginController.cs(44,62): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) ...

我在这上面花了好几个小时。令我沮丧的是,它是在我的机器上的 visual studio 中构建的,而不是使用 msbuild 在服务器上构建的。

赛斯

最佳答案

右键单击该项目并单击“卸载”,然后再次单击“编辑”。

找到 <Reference>对于 System.Web.Mvc .如果<HintPath>没有提到“包”目录(或丢失),那就是你的问题。只需删除包和所有引用并重新开始。

NuGet 包还原仅还原磁盘上的文件,它不会更新项目引用。

关于asp.net-mvc - 如何让 MSBuild 使用被引用为 nuget 包的 MVC 程序集来构建我的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12753887/

相关文章:

asp.net-mvc - 从 ASP.Net MVC 生成 PDF 和 Excel 文件的最佳方法是什么

jquery - 将 jqGrid 行数据从 View 提交到 Controller - 什么方法?

c# - 根据 Date 对表进行排序,在 mvc 4 中使用 Linq 查询

c# - 在 Windows Phone 8 应用程序中使用 Windows Live ID 身份验证

visual-studio-2010 - 如何将 100 多个 Visual Studio 安装程序项目 (vdproj) 转换为 Wix 安装程序?

c++ - 非源文件更改时触发构建

.net - 为什么 Microsoft 的新 .NET 代码不兼容 Microsoft StyleCop?

c# - 在 Web.config 中使用 configSource 时,不支持使用 EntityFramework 的脚手架 Controller 或 View

c# - 在 MVC 应用程序中使用 await Task<T> async 挂起 Controller

c# - ASP.NET MVC4 ... "BIN"是保留关键字吗?