【问题标题】:Building site via devenv.exe works, msbuild fails通过 devenv.exe 构建站点有效,msbuild 失败
【发布时间】:2023-03-06 04:58:01
【问题描述】:

我正在使用 TFS2012 进行 VS2012 Update 3。

我使用 devenv 和 msbuild 构建了相同的解决方案。当我进入网站项目时,devenv 不会报告任何错误,但 msbuild 会反复报告。两者的日志示例:

开发者:

114>------ Build started: Project: C:\...\API\, Configuration: Debug Any CPU ------  
114>Could not get dependencies for project reference 'A'Could not get dependencies for     project reference 'BusinessLogic' Could not get dependencies for project reference 'BusinessLogic.ASPAgents' Could not get dependencies for project reference 'DataAccessLogicComponents' Could not get dependencies for project reference 'UI'Validating Web Site
114>Building directory '/API/'.  
114>  
114>Validation Complete

MSBuild:

121>C:\Scrubbed\API.metaproj : warning MSB3274: The primary reference "C:\Scrubbed\PreMVC\A\bin\Release\A.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".  
121>C:\Scrubbed\API.metaproj : warning MSB3274: The primary reference "C:\Scrubbed\PreMVC\BusinessLogic\bin\Release\A.Web.BusinessLogic.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".  
121>C:\Scrubbed\API.metaproj : warning MSB3275: The primary reference "C:\Scrubbed\PreMVC\BusinessLogic\bin\Release\A.Web.BusinessLogic.dll" could not be resolved because it has an indirect dependency on the assembly "A, Version=0.0.0.15, Culture=neutral, PublicKeyToken=060d385c0c45e767" which was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".  

     C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /API -p PreMVC\API\ -u -f PrecompiledWeb\API\ 

121>C:\Scrubbed\PreMVC\API\App_Code\File1.cs(7): error CS0234: The type or namespace name 'BusinessLogic' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]  
121>C:\Scrubbed\PreMVC\API\App_Code\File1.cs(8): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]  
121>C:\Scrubbed\PreMVC\API\App_Code\File1.cs(12): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]  
121>C:\Scrubbed\PreMVC\API\App_Code\File2.cs(7): error CS0234: The type or namespace name 'BusinessLogic' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]
121>C:\Scrubbed\PreMVC\API\App_Code\File2.cs(8): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]  
121>C:\Scrubbed\PreMVC\API\App_Code\File2.cs(12): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]
121>C:\Scrubbed\PreMVC\API\App_Code\File3.cs(7): error CS0234: The type or namespace name 'BusinessLogic' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]
121>C:\Scrubbed\PreMVC\API\App_Code\File3.cs(8): error CS0234: The type or namespace name 'UI' does not exist in the namespace 'A.Web' (are you missing an assembly reference?) [C:\Scrubbed\API.metaproj]  
121>Done Building Project "C:\Scrubbed\API.metaproj" (Rebuild target(s)) -- FAILED.

知道为什么 Devenv 继续运行但 MSBuild 立即失败?

【问题讨论】:

  • 从命令提示符运行 devenv 可能与使用 msbuild 不同,因为它可能会引入一些对 msbuild 不起作用的用户/ui 设置。只是一个偶然的想法。

标签: asp.net msbuild devenv


【解决方案1】:

我从 MSDN 论坛上的一个模组得到了答案。基本上,MSBuild 对 devenv 只是发出警告但继续执行的依赖关系非常严格。

我们最终获得了完全迁移到 .NET 4.5 的许可,因此我们修复了不匹配问题并最终将构建迁移到了 MSBuild。

【讨论】:

    【解决方案2】:

    确保将项目引用添加到其他项目,并且它们都使用相同版本的 .NET 框架。

    【讨论】:

    • 我在问为什么一个似乎工作,一个似乎失败。无论如何,我将项目更新到 .NET 4.5 并切换到 MSBuild,因为 devenv 随机(有时 - 像 15 个构建中的 1 个)存在“任务被取消”问题。
    【解决方案3】:

    您的日志中的警告没有说明问题吗?

    "121>C:\Scrubbed\API.metaproj : 警告 MSB3274: 主要参考 "C:\Scrubbed\PreMVC\A\bin\Release\A.dll" 无法解析,因为它是针对 " .NETFramework,Version=v4.5" 框架。这是比当前目标框架".NETFramework,Version=v4.0" 更高的版本。"

    【讨论】:

    • 问题(我认为)是为什​​么它对一个有效,而对另一个无效。
    最近更新 更多