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

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


当前回答

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" />.

其他回答

我在对具有纯内容项目的MonoGame解决方案进行干净的CLI重建时遇到了这个问题。

解决方案是向每个内容项目添加一个带有空构造函数的虚拟类文件。

六年后,在升级到Visual Studio 2015时,又遇到了同样的问题。因为这个特解不在我加进去的这个列表里。

c:\windows\system32…文件夹中。 将它们移动到一个非系统文件夹,并添加一个对新文件夹的引用,最终解决了这个问题。其余的问题确实是其他人已经在这里说过的

好吧,之前的答案都不适合我,所以这让我思考为什么我要点击,作为开发者我们应该尝试着理解这里发生了什么。

在我看来,这个不正确的元数据文件引用必须保存在某个地方。

对.csproj文件的快速搜索显示了错误的代码行。我有一个名为<itemGroup>的部分,它似乎挂在了旧的不正确的文件路径上。

<ItemGroup>
    <ProjectReference Include="..\..\..\MySiteOld\MySite.Entities\MySite.Entities.csproj">
        <Project>{5b0a347e-cd9a-4746-a3b6-99d6d010a6c2}</Project>
        <Name>Beeyp.Entities</Name>
    </ProjectReference>
...

所以一个简单的解决方法是:

备份.csproj文件。 在.csproj文件中找到不正确的路径并适当地重命名。

请确保在修改之前备份了旧的.csproj。

我也犯了同样的错误。它隐藏在下面的路径。 DLL文件的路径类似于“D:\Assemblies Folder\Assembly1.dll”。

但是程序集引用的原始路径是“D:\Assemblies%20Folder\Assembly1.dll”。

由于此路径名称变化,无法从其原始路径检索程序集,因此抛出“未找到元数据”错误。

解决方案是在堆栈溢出问题我如何替换所有的空格与%20在c# ?

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

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

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

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

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