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

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


当前回答

建议的答案对我不起作用。这个错误是另一个问题的诱饵。

我发现我的目标是一个略有不同的。net版本,这被编译器标记为警告,但它导致构建失败。 这应该被标记为错误,而不是警告。

其他回答

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

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

对.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。

在我的案例中,ReSharper是愚蠢的,即使我的项目目标是c# 6,我也被提供了重构来使用c# 7独有的特性。

出于这个原因,我最终修改了这段代码,

private DateTime? _joinedDate;
[Column(TypeName = "DateTime2")]
public DateTime JoinedDate
{
    get { return _joinedDate ?? DateTime.Now; }
    set { _joinedDate = value; }
}

进入这段代码:

private DateTime? _joinedDate;
[Column(TypeName = "DateTime2")]
public DateTime JoinedDate
{
    get => _joinedDate ?? DateTime.Now;
    set => _joinedDate = value;
}

由于某种原因,让getter和setter使用表达式体使编译器产生元数据错误而不是语法错误。

删除bin/obj文件夹,然后重新构建项目对我来说很有效。

在我的情况下,我认为发生的是,我经历了一个运行时错误,我第一次构建项目,所以我的dll文件不是没有生成。

这发生在从另一个项目引用一个项目时。我引用的项目就是有问题的那个。

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.

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

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

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