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

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


当前回答

我使用Visual Studio 2019得到了同样的错误。 在仔细研究了后台发生的事情后,我发现在追加的类库上有错误,这反过来又没有正确编译,同时通过错误“元数据文件未找到”。纠正错误,重新编译,所有工作。

在我的例子中,答案是在输出选项卡的分析中找到的。

其他回答

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.

在我的情况下,我有一堆其他的构建错误(一些简单的类型转换)以及这个,我抓着我的头试图解决这个问题,我没有关注其他错误。

最终解决我的问题的是,我修复了所有其他构建错误,然后我再次构建,它成功构建。

因此,如果您有其他构建错误以及丢失的DLL文件错误,并且没有其他方法为您工作,则尝试先修复其他错误,然后再次构建解决方案。

我在打开一个实体框架被引用的项目后收到了这个错误,所以我删除了这些引用,并通过pthe socket管理器重新安装了实体框架6.0.0.0版本:

install-package entityframework -version 6.0.0.0

错误仍然在显示,所以我认为那些引用在那里,因为有一个旧版本的实体框架应该“预安装”在项目中,但它并没有真正工作。

所以我去找文件包。Config,并注意到有另一个引用:

<packages>
  **<package id="EntityFramework" version="5.0.0" targetFramework="net45" />**
  <package id="EntityFramework" version="6.0.0" targetFramework="net45" />
</packages>

然后我删除了这一行,清理并重新构建了项目和容器解决方案,它最终工作了。

我使用Visual Studio 2019得到了同样的错误。 在仔细研究了后台发生的事情后,我发现在追加的类库上有错误,这反过来又没有正确编译,同时通过错误“元数据文件未找到”。纠正错误,重新编译,所有工作。

在我的例子中,答案是在输出选项卡的分析中找到的。

The Visual Studio IDE doesn't do any building behind the scenes, the Msbuild application does. The VS IDE essentially just constructs the project file that is used by Msbuild and quite often it makes mistakes if you leave it up to the IDE to figure things out on it's own. If you are getting the Metadata file '.dll' could not be found error it is likely due to the fact that the correct/expected assemblies are not being found. So perhaps Visual Studio might be creating a project file for a 4.5 framework app, and expecting 4,5 assemblies, while you are referencing 4.0 assemblies. So look at your Visual Studio settings for incompatibilities or go into the project file yourself, and manually fix it by specifying the correct path <Reference Include="C:\\correct path to assembly\\yourAssembly.dll" />.