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

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


当前回答

根据错误消息,我认为文件路径没有被截断。它看起来是不正确的。如果我正确地阅读消息,它似乎正在寻找DLL文件在…

工作= - \ VersionManagementSystem \ BusinessLogicLayer \ bin \ \工具调试\ BusinessLogicLayer.dll

这不是有效路径。是否可能将构建过程中的宏定义设置为无效值?

其他回答

好吧,我的答案不只是所有解决方案的总结,但它提供了更多。

节(1):

一般解决方案:

我有四个这样的错误(“元数据文件找不到”),还有一个错误是“源文件无法打开(“未指定的错误”)”。

我试图摆脱'元数据文件找不到'错误。为此,我阅读了许多文章,博客等,发现这些解决方案可能是有效的(总结在这里):

Restart Visual Studio and try building again. Go to 'Solution Explorer'. Right click on Solution. Go to Properties. Go to 'Configuration Manager'. Check if the checkboxes under 'Build' are checked or not. If any or all of them are unchecked, then check them and try building again. If the above solution(s) do not work, then follow sequence mentioned in step 2 above, and even if all the checkboxes are checked, uncheck them, check again and try to build again. Build Order and Project Dependencies: Go to 'Solution Explorer'. Right click on Solution. Go to 'Project Dependencies...'. You will see two tabs: 'Dependencies' and 'Build Order'. This build order is the one in which solution builds. Check the project dependencies and the build order to verify if some project (say 'project1') which is dependent on other (say 'project2') is trying to build before that one (project2). This might be the cause for the error. Check the path of the missing .dll: Check the path of the missing .dll. If the path contains space or any other invalid path character, remove it and try building again. If this is the cause, then adjust the build order.


节(2):

我的具体情况是:

我尝试了上面所有的步骤,并重新启动了几次Visual Studio。但是,这并没有帮助我。

所以,我决定摆脱我遇到的其他错误('源文件无法打开('未指明的错误')')。

我看到一篇博客文章:TFS错误-源文件无法打开(“未指明的错误”)

我尝试了那篇博客文章中提到的步骤,我摆脱了“源文件无法打开(“未指明的错误”)”的错误,令人惊讶的是,我摆脱了其他错误(“元数据文件无法找到”)。


节(3):

这个故事的寓意:

尝试上文第(1)节中提到的所有解决方案(以及任何其他解决方案)来消除错误。如果没有解决问题,按照上面第(2)节中提到的博客,从.csproj文件中删除源代码控制和文件系统中不再存在的所有源文件的条目。

我用的是VS 2019。我们集团预计从2017年升级到2019年。

实际解决方案

我试图克隆到我的C:驱动器上的一个文件夹,这是我漫游配置文件的一部分(所以在网络上)。我创建了一个本地文件夹,它保证不会被跟踪,而是被克隆到那里。这些问题都消失了。

注:

这不可能是路径长度问题,因为我还尝试将其克隆到名称比原始路径长的文件夹中,结果构建良好。 这不可能是因为文件名中有空格,因为我们的解决方案文件夹中有空格。 这个问题似乎只影响VS2019,而不影响VS2017。虽然我们以前遇到过漫游配置文件的问题,但它通常发生在我们尝试与Git同步时,而不是构建时。

我试过的其他方法都没用

重新启动VS,注销,重新启动等。 从DevOps回购中删除解决方案并重新克隆 我们的代码中没有构建错误 取消选中并重新选中“生成配置”框 构建顺序是有意义的 所有。net框架的目标都是一样的。(对我来说是4.6。可能并不重要。) dll实际上存在于path中 重新加载项目 重新安装NuGet包 重新添加dll

对我来说,问题发生了,因为我是内联变量。

因此,以下是成功的构建:

ReportCategory reportCategoryEnum;
Enum.TryParse(reportCategory, true, out reportCategoryEnum);

而当我修改我的代码如下,没有错误显示,但构建失败

Enum.TryParse(reportCategory, true, out ReportCategory reportCategoryEnum);

在我的案例中,解决方案中的一些项目针对任何CPU,其中一些针对x86。在整个解决方案统一了平台目标后,编译错误消失了。

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

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

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

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