C# 如何在没有任何错误或警告的情况下找到构建失败的原因

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13239325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 07:53:02  来源:igfitidea点击:

How to find reason of failed Build without any error or warning

c#asp.netvisual-studio-2010

提问by Abhijeet

I have a WebApplication which contains reference to WCF services.

我有一个包含对 WCF 服务的引用的 WebApplication。

While building using Visual Studio 2010, Build fails without any error or warning. However building the .csprojusing MsBuildis successful.

使用 Visual Studio 2010 构建时,构建失败,没有任何错误或警告。但是构建.csproj使用MsBuild是成功的。

Can't figure out what should I try in Visual Studio, to resolve / diagnose the issue. Can you please help out?

无法弄清楚我应该在 Visual Studio 中尝试什么来解决/诊断问题。你能帮忙吗?

EDIT:

编辑:

I find out that the build has been failing,

我发现构建失败了,

  1. From text displayed in status Bar.
    enter image description here

  2. From output window :

    ========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
    
  1. 来自状态栏中显示的文本。
    在此处输入图片说明

  2. 从输出窗口:

    ========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
    

采纳答案by Richard J Foster

I just ran into a similar situation. In my case, a custom action (from the MSBuildVersioning package available on Nuget.org - http://www.nuget.org/packages/MSBuildVersioning/) which appeared in the csproj file's BeforeBuild target was failing without triggering any error message in the normal place.

我刚刚遇到了类似的情况。就我而言,出现在 csproj 文件的 BeforeBuild 目标中的自定义操作(来自 Nuget.org 上提供的 MSBuildVersioning 包 - http://www.nuget.org/packages/MSBuildVersioning/)失败,但未在正常的地方。

I was able to determine this by setting the MSBuild project build output verbosity (in Visual Studio's Options / Projects and Solutions / Build and Run setting area) to "Diagnostic" as shown below. This then showed that the custom action (in my case HgVersionFile) was what had failed.

我能够通过将 MSBuild 项目构建输出详细程度(在 Visual Studio 的选项/项目和解决方案/构建和运行设置区域)设置为“诊断”来确定这一点,如下所示。然后这表明自定义操作(在我的情况下为 HgVersionFile)失败了。

Screen capture from Visual Studio showing the modified setting.

来自 Visual Studio 的屏幕截图,显示了修改后的设置。

回答by Sasse

  • If solution contains more than one project, try building them one at a time.
  • Try restart Visual Studio.
  • Try restart Computer.
  • Try "Rebuild all"
  • Try "Clean Solution" then remove your "vspscc" files and "vssscc" files and then restart Visual Studio and then "Rebuild All".
  • 如果解决方案包含多个项目,请尝试一次构建一个。
  • 尝试重新启动 Visual Studio。
  • 尝试重新启动计算机。
  • 尝试“全部重建
  • 尝试“清理解决方案”,然后删除“ vspscc”文件和“ vssscc”文件,然后重新启动 Visual Studio,然后“全部重建”。

回答by toddmo

This happened to me after adding a new page to an asp.net project.

在向 asp.net 项目添加新页面后,这发生在我身上。

What I did was exclude the page, get it to build again successfully.

我所做的是排除页面,让它再次成功构建。

Then I added back the page with all the code commented out. Success.

然后我将所有代码都注释掉的页面重新添加回来。成功。

Then I uncommented the code bit by bit and then it all worked.

然后我一点一点地取消注释代码,然后一切正常。

回答by Ignas Vy?nia

VS (2013 Pro, Win 8.1) restart did it for me.

VS(2013 Pro,Win 8.1)重启为我做了。

回答by Santosh K

Firstly "Clean the Solution" , then Rebuild soln.

首先“清理解决方案”,然后重建解决方案。

If won't work close the Solution and restart the solution.

如果不起作用,请关闭解决方案并重新启动解决方案。

Try these things, hope definitely works.

试试这些东西,希望绝对有效。

回答by user764754

I want to expand on Sasse's answer.

我想扩展Sasse 的回答

To fix the problem with Visual Studio 2015 Update 2 I had to build each project one at a time and look at the output window after each build.

为了解决 Visual Studio 2015 Update 2 的问题,我必须一次构建一个项目,并在每次构建后查看输出窗口。

One project gave me

一个项目给了我

"The type or namespace name 'SomeNamespace' does not exist in the namespace 'BeforeSomeNamespace' (are you missing an assembly reference?)".

“命名空间‘BeforeSomeNamespace’中不存在类型或命名空间名称‘SomeNamespace’(您是否缺少程序集引用?)”。

There was no error in the Error List window but the assembly had a yellow warning sign under "References".

错误列表窗口中没有错误,但程序集在“参考”下有一个黄色警告标志。

I then saw that the referencing project targeted 4.5.1 and the referenced project 4.6.1. Changing 4.6.1 to 4.5.1 allowed the overall build to succeed.

然后我看到引用项目的目标是 4.5.1,而引用的项目是 4.6.1。将 4.6.1 更改为 4.5.1 使整体构建成功。

回答by Ben Whitmore

I had a similar problem after adding a new project (called "TestCleaner") to my solution: Build failed, no errors.

在我的解决方案中添加一个新项目(称为“TestCleaner”)后,我遇到了类似的问题:构建失败,没有错误。

I increased output verbosity (see Richard J Foster's instructions) and searched the output for "failed". I quickly discovered which project was failing, and why: project "TestRunner" had failed with "error CS0246: The type or namespace name 'TestCleaner' could not be found"(even though no problems were highlighted in the code).

我增加了输出详细程度(请参阅 Richard J Foster 的说明)并在输出中搜索“失败”。我很快发现了哪个项目失败了,以及为什么:项目“TestRunner”失败了“错误 CS0246:找不到类型或命名空间名称‘TestCleaner’”(即使代码中没有突出显示任何问题)。

Checking TestRunner's references, sure enough the reference to TestCleaner was marked as unresolved, and the path was missing from the reference properties. Deleting and re-adding didn't fix it. Again, no explanation why.

检查 TestRunner 的引用,果然对 TestCleaner 的引用被标记为未解析,并且引用属性中缺少路径。删除并重新添加并没有解决它。再次,没有解释为什么。

unresolved reference

未解决的参考

I finally discovered the cause: "TestCleaner" was using a different target framework to the other projects. It was .Net 4.5.2; the others were 4.5.

我终于发现了原因:“TestCleaner”使用了与其他项目不同的目标框架。它是 .Net 4.5.2;其他人是4.5。

回答by Andy

Nothing was working for me so I deleted the .suo file, restarted VS, cleaned the projected, and then the build would work.

没有什么对我有用,所以我删除了 .suo 文件,重新启动了 VS,清理了投影,然后构建就可以工作了。

回答by Alan Thomas

Seems that there are multiple answers to this question, so I'll add mine from personal experience hoping it will save someone time/stress.

似乎这个问题有多种答案,所以我会根据个人经验添加我的经验,希望它能节省一些人的时间/压力。

Make sure all the projects in your solution are targeting the same .NET version.

确保解决方案中的所有项目都针对相同的 .NET 版本。

Similar to OP, there were 0 errors but the build kept failing. However, there was one warning entry (buried in between several hundred useless XML warnings...) saying that one project was targeting a different .NET version than a project that was referencing it. The entire issue was that one project within my solution was targeting .NET 4.5.2, when the rest were targeting 4.5.1. It shouldwork even with this discrepancy (hence why it was just a warning) but unfortunately, it broke the build.

与 OP 类似,有 0 个错误,但构建一直失败。但是,有一个警告条目(隐藏在数百个无用的 XML 警告之间......)说一个项目针对的 .NET 版本与引用它的项目不同。整个问题是我的解决方案中的一个项目针对 .NET 4.5.2,而其余项目针对 4.5.1。即使存在这种差异,它也应该可以工作(因此它只是一个警告),但不幸的是,它破坏了构建。

The strange part was that it built/ran fine for a while, but suddenly the build started failing one time causing this issue. Not sure what I did for it to start complaining about differing .NET target versions, but I feel that there are just some mysteries in Visual Studio that will never be solved.

奇怪的是,它构建/运行了一段时间,但突然构建开始失败,导致此问题。不知道我做了什么才开始抱怨不同的 .NET 目标版本,但我觉得 Visual Studio 中只有一些永远无法解决的谜团。

回答by Bill Yang

On other possibility is that Visual Studio needs to run as Administrator, this might be related to deploying to local IIS server or other deployment need.

另一种可能性是 Visual Studio 需要以管理员身份运行,这可能与部署到本地 IIS 服务器或其他部署需要有关。