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

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


当前回答

右键单击解决方案并单击Clean。 右键单击解决方案并单击Rebuild。

其他回答

在解决方案文件夹中删除包含NuGet的packages文件夹对我来说是有效的。重建之后,一切都恢复正常了。检查解决方案中的引用,并检查带有黄色三角形的引用。

例图:

当我进行构建时,它通常会在Visual Studio 2017中显示如下错误:

Error   CS0006  Metadata file 'C:\src\ProjectDir\MyApp\bin\x64\Debug\Inspection.exe' could not be found MyApp   C:\src\ProjectDir\MyApp\CSC 1   Active

但有时这样的错误会显示几秒钟,然后它就会消失,切换回上面的消息:

Error   CS1503  Argument 1: cannot convert from 'MyApp.Model.Entities.Asset' to 'MyApp.Model.Model.Entities.Inspection' MyApp   C:\src\ProjectDir\MyApp\ViewModels\AssetDetailsViewModel.cs 1453    Active

所以我花了时间解决第一个错误,但真正的问题是由于第二个错误。首先,我必须删除所有的/bin和/obj目录,然后我还删除了上面提到的.suo文件。这使我将问题缩小到接口问题。

在我的界面中,我有这样的:

    Task<IList<Defect>> LoadDefects(Asset asset);

但在我的实际实现中,我有这样的代码:

    public virtual async Task<IList<Defect>> LoadDefects(Inspection inspection)
    {
       var results ...
       // ....

        return results;
    }

在我更新界面后,构建成功完成:

    Task<IList<Defect>> LoadDefects(Inspection inspection);

所以看起来在VS中缓存导致它一直显示CS0006错误,而实际的问题是CS1503错误。

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 2019中:

关闭Visual Studio。 删除位于同一目录中的.vsccc文件 文件夹作为解决方案文件。 打开解决方案并重新构建。

我正在运行Visual Studio 2013。

似乎构建依赖项是不正确的。删除“*”。suo文件确实解决了我遇到的问题。