我在一个WPF, c# 3.0项目上工作,我得到了这个错误:

Error 1 Metadata file
'WORK=- \Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug
\BusinessLogicLayer.dll' could not be found C:\-=WORK=- \Tools
\VersionManagementSystem\VersionManagementSystem\CSC VersionManagementSystem

这是我如何引用我的usercontrols:

xmlns:vms="clr-namespace:VersionManagementSystem"
<vms:SignOffProjectListing Margin="5"/>

每次构建失败后都会发生这种情况。我能得到解决方案编译的唯一方法是注释掉所有用户控件并重新构建项目,然后取消注释用户控件,一切正常。

我已经检查了构建顺序和依赖项配置。

正如你所看到的,它似乎截断了DLL文件的绝对路径…我读到过关于长度的问题。这是一个可能的问题吗?

注释、构建和取消注释是非常烦人的,构建变得非常烦人。


当前回答

在我的案例中,依赖项目(取决于错误消息中的项目)在项目的“属性→应用程序→程序集信息……”下的“程序集版本”字段中缺少值。我只是在“文件版本”中添加了相同的数字,点击“确定”,编译器错误就消失了!

事实证明,重新添加AssemblyVersion然后再次构建项目会导致另一个错误,该错误声称它已经出现在项目中。这是!在解决方案资源管理器中项目的属性节点下,有一个“SolutionVersionInfo.cs”文件,该文件还包含一个装配版本属性-从项目中删除该文件解决了此错误。

其他回答

在Visual Studio的新版本中仍然会发生这种情况(我刚刚在Visual Studio 2013中发生了这种情况):

另一种方法是关闭Visual Studio并删除.sln文件旁边的.suo文件。(它将在下次保存全部(或退出Visual Studio)时重新生成)。

当我在另一台机器上向解决方案中添加新项目时,我就遇到过这个问题,但.suo文件在其他情况下也可能被损坏,导致非常奇怪的Visual Studio行为,所以删除它是我一直尝试的事情之一。

注意,删除.suo文件将重置解决方案的启动项目。

关于.suo文件的更多信息在这里。

在我的案例中,问题是我手动删除了一个标记为“缺失”的非编译文件。一旦我删除了对现在丢失的文件的引用并重新编译-一切都很好。

In my case it happened to me when I was referencing NuGet packages locally and moved their directory to somewhere else, I changed the path inside NuGet.Config but unfortunately I discovered that I should change the .csproject files manually to update the reference path, but the error message CS0006 was way far from describing this problem. Generally it also happens when there is a reference to DLL that couldn't be found, to be able to identify issue search your references in the project with the problem you will find some references with warning icon associated with them, try fixing those and it should work as expected.

我的问题实例是由一个公共项目引起的,该项目中有重复的类名(在不同的文件名下)。奇怪的是,Visual Studio无法检测到这一点,而只是破坏了构建过程。

在我的案例中,问题是由一个简单的构建错误引起的,

事件“XYZ”从未被使用过

不管出于什么原因,它都没有显示在错误窗口中。

因此,Visual Studio构建系统似乎忽略了这个错误,并试图构建依赖的项目,这反过来又以恼人的元数据消息失败。

建议是——尽管听起来很愚蠢——

首先看看你的输出窗口!

我花了半个小时才想到这个主意。