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

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

不知道我应该在Visual Studio中尝试什么来解决/诊断问题。你能帮帮我吗?

我发现构建一直在失败,

从状态栏中显示的文本。 从输出窗口: ========== 构建:0成功或更新,1失败,0跳过 ========== 输出选项卡包含配置详细信息。 ------构建开始:项目:<projectName here>配置:调试任何CPU


当前回答

这里有一些你可以尝试的方法:

If your solution contains more than one project, try building each project one at a time. (You may even want to try opening each project independently of the solution.) If applicable, ensure that all of your projects (including dependencies and tests) target the same version of the .NET Framework. (Thanks to user764754 for this suggestion!) Tip: Check Tools → Extension and Updates to ensure that your packages are up-to-date. Ensure that all dependency projects are built to target the same platform as your main project. Try restarting Visual Studio. As suggested by Bill Yang, try running Visual Studio as Administrator, if you aren't already. (If you are already running Visual Studio as Administrator, perhaps try the opposite?) Try restarting your computer. Try "Rebuild All". Run "Clean Solution", then remove your *vspscc* and *vssscc* files, restart Visual Studio, and then "Rebuild All". As suggested by Andy, close Visual Studio, delete the .suo file, and restart Visual Studio. As suggested by Arun Prasad E S, close Visual Studio, delete the .vs folder in your solution directory, and then re-open Visual Studio. (This folder is auto-generated by Visual Studio and contains cache, configuration settings, and more. More details can be found in these questions: Visual Studio - Deleting .vs folder and https://stackoverflow.com/q/48897191.) As suggested by MrMalith, close Visual Studio, delete the obj folder in your solution directory, clear your temporary folder, and then re-open Visual Studio.

其他回答

这里有一些你可以尝试的方法:

If your solution contains more than one project, try building each project one at a time. (You may even want to try opening each project independently of the solution.) If applicable, ensure that all of your projects (including dependencies and tests) target the same version of the .NET Framework. (Thanks to user764754 for this suggestion!) Tip: Check Tools → Extension and Updates to ensure that your packages are up-to-date. Ensure that all dependency projects are built to target the same platform as your main project. Try restarting Visual Studio. As suggested by Bill Yang, try running Visual Studio as Administrator, if you aren't already. (If you are already running Visual Studio as Administrator, perhaps try the opposite?) Try restarting your computer. Try "Rebuild All". Run "Clean Solution", then remove your *vspscc* and *vssscc* files, restart Visual Studio, and then "Rebuild All". As suggested by Andy, close Visual Studio, delete the .suo file, and restart Visual Studio. As suggested by Arun Prasad E S, close Visual Studio, delete the .vs folder in your solution directory, and then re-open Visual Studio. (This folder is auto-generated by Visual Studio and contains cache, configuration settings, and more. More details can be found in these questions: Visual Studio - Deleting .vs folder and https://stackoverflow.com/q/48897191.) As suggested by MrMalith, close Visual Studio, delete the obj folder in your solution directory, clear your temporary folder, and then re-open Visual Studio.

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

我尝试了很多事情,比如重新启动Visual Studio,清理并重新构建解决方案,重新启动PC等,但没有一个对我有效。我最终通过以下方法解决了这个问题:

首先,确保解决方案中的所有项目(包括测试)的目标都是相同的. net版本。然后:

保存项目中挂起的更改并关闭Visual Studio 从文件资源管理器中找到准确的位置,找到“obj”文件并打开它, 然后,删除所有包含的文件(有些文件不会删除,没关系,跳过它们)。 使用运行命令(按Windows键+ R),输入“%temp%”,按enter找到临时文件。 最后,将它们全部删除。

我想扩展一下萨斯的答案。我必须针对正确的. net版本来解决这个问题。

一个项目给了我一个错误:

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

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

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

删除隐藏的.vs文件夹并重新启动Visual Studio。这对我很管用。