我在一个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文件的绝对路径…我读到过关于长度的问题。这是一个可能的问题吗?

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


当前回答

问题的原因可能是您在解决方案中混合添加了对DLL文件和项目的引用。

如果你有项目A、B和C:

A引用B和C作为解决方案中的项目。 B引用C作为DLL文件(引用文件)

您可以单独构建每个项目,但无法重新构建以以下内容结尾的解决方案:找不到元数据文件“C.dll”。

在解决方案中将引用从文件更改为项目会有所帮助。

其他回答

到目前为止,这几十个答案中没有一个对我有用。在我的情况下,我也得到了错误:

元组元素名称“Value”被推断出来。请使用语言版本7.1或更高的版本通过推断的名称访问元素

这出现在构建时“元数据文件'.dll'找不到”错误旁边,但它很快就消失了,因为错误有时会在IDE“赶上”。

双击错误以找到它,并删除有问题的代码,修复它。

否则,你可以在Visual Studio中试试这个:

菜单项目→<项目名称>属性→构建→按钮高级→语言版本→c# <最新小版本>(例如:“c# 5.0”)

这也能解决问题。

看起来“元数据文件“.dll”无法找到”通常是一些其他潜在问题的症状,因此,如果没有一个顶级解决方案对您有效,请检查其他错误和警告,并尝试找到真正的问题。

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

几年后再回到这个问题,这个问题很可能与Windows的最大路径限制有关:

命名文件,路径和命名空间,最大路径长度限制

我在一个.csproj文件中有一个合并冲突,最终得到了一个构建目标的两个副本。

<编译包含=“SystemCodes\APSystemCodes.cs” />

在我消除了复制构建工作。

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.