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

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


当前回答

VS2022:在这里的大量列表中没有发现原因。

拥有一个完全由静态方法组成的静态类。从类声明中删除static不会引发编译错误或警告,但会导致OP构建错误。

将类声明恢复为静态并修复了该问题。

其他回答

这类错误看起来与Visual Studio没有提供关于错误的正确信息有关。开发人员甚至不理解构建失败的原因。它可能是语法错误或其他原因。通常,要解决这类问题,您应该找到问题的根源(例如,查看构建日志)。

在我的例子中,问题实际上是错误列表窗口没有显示任何错误。但确实有语法错误;我在输出窗口中发现了这些错误,在修复它们之后,问题就解决了。

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

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

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

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

正如用户@burzhuy指出的那样,查看Outputwindow,而不仅仅是错误列表窗口是很重要的。

在我的例子中,我正在对Roslyn编译器进行修改。它的构建项目会运行额外的检查,以查看公共字段是否与定义为编译器公共接口的字段一致,否则将产生RS0016或RS0017错误。我已经添加了几个公共字段,并通过将鼠标悬停在错误上并选择“添加到公共API”来修复RS0016错误。

后来我改变了主意,将公共字段移到了另一个类中。出于某种原因,这产生了“元数据文件无法找到错误”,我摆弄得越多,得到的错误就越多。

您需要找到正确的publicapi . unshipping .txtfile(在我的情况下,它是在E:\Roslyn\32414\src\Compilers\Core\Portable),并手动编辑它以删除不再相关的行。

导航到解决方案的文件夹资源管理器并删除抛出错误的未使用的项目文件夹。在我的例子中,在删除项目后,文件夹仍然存在于目录中。删除文件夹后解决方案构建成功!