C# 找不到元数据文件“.dll”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1421862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 16:21:49  来源:igfitidea点击:

Metadata file '.dll' could not be found

c#.netwpfvisual-studio-2008c#-3.0

提问by Oliver

I am working on a WPF, C# 3.0 project, and I get this error:

我正在处理 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

This is how I reference my usercontrols:

这是我引用我的用户控件的方式:

xmlns:vms="clr-namespace:VersionManagementSystem"
<vms:SignOffProjectListing Margin="5"/>

It happens after every failed build. The only way I can get the solution to compile is to comment out all my user controls and re-build the project, and then I uncomment the usercontrols and everything is fine.

它发生在每次失败的构建之后。我可以获得编译解决方案的唯一方法是注释掉我所有的用户控件并重新构建项目,然后我取消注释用户控件,一切都很好。

I have checked build orders and dependencies configurations.

我已经检查了构建顺序和依赖项配置。

As you can see, it seems to have truncated the DLL file's absolute path... I have read that there is a bug with the length. Is this a possible problem?

正如你所看到的,它似乎截断了 DLL 文件的绝对路径......我读到有一个长度错误。这是一个可能的问题吗?

It's very annoying and having to comment, build, and uncomment, the build is becoming extremely tiresome.

这是非常烦人的,必须评论、构建和取消注释,构建变得非常令人厌烦。

采纳答案by Matt_Bro

I just had the same problem. Visual Studio isn't building the project that's being referenced.

我只是遇到了同样的问题。Visual Studio 不会构建被引用的项目。

Written Instructions:

书面说明:

  1. Right click on the solution and click Properties.
  2. Click Configuration on the left.
  3. Make sure the check box under "Build" for the project it can't find is checked. If it is already checked, uncheck, hit apply and check the boxes again.
  4. (Optional) You had to do it for both Release and Debug modes on the solution properties.
  1. 右键单击解决方案,然后单击“属性”。
  2. 单击左侧的配置。
  3. 确保它无法找到的项目的“构建”下的复选框被选中。如果它已经被选中,取消选中,点击应用并再次选中复选框。
  4. (可选)您必须针对解决方案属性的发布和调试模式执行此操作。

Screen capture Instructions:

屏幕截图说明:

  • They say a picture is worth a thousand words. Click on the GIF to zoom in, and hopefully it will be easy to follow:
  • 他们说,一张图片胜过千言万语。点击 GIF 放大,希望它很容易理解:

Gif Instructions

动图说明

回答by JaredPar

Based on the error message I don't believe the file path is being truncated. It looks to just be incorrect. If I'm reading the message correctly it appears to be looking for the DLL file at ...

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

WORK=-\Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug\BusinessLogicLayer.dll

WORK=-\Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug\BusinessLogicLayer.dll

This is not a valid path. Is it possible that you have a macro definition in the build process set to an invalid value?

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

回答by JaredPar

I also met this problem. Firstly you have to manually build you DLL project, by right-click, Build. Then it will work.

我也遇到了这个问题。首先,您必须通过右键单击 Build 手动构建 DLL 项目。然后它会起作用。

回答by Chris Moschini

For me, it was trying to find a DLL in a path that used to contain the Project, but we'd moved it to a new directory. The Solution had the correct path to the Project, but Visual Studio somehow kept looking in the old location.

对我来说,它试图在曾经包含该项目的路径中找到一个 DLL,但我们已将其移动到一个新目录。解决方案有正确的项目路径,但 Visual Studio 不知何故一直在旧位置查找。

Solution: Rename each problem Project - just add a character or whatever - then rename it back to its original name.

解决方案:重命名每个问题项目 - 只需添加一个字符或其他任何东西 - 然后将其重命名回其原始名称。

This must reset some global cache of some kind in Visual Studio, because this clears both this issue up and several like it, while things like Clean do not.

这必须在 Visual Studio 中重置某种全局缓存,因为这会清除这个问题和几个类似的问题,而像 Clean 这样的东西不会。

回答by Oliver

Coming back to this a few years later, this problem is more than likely related to the Windows maximum path limit:

几年后回到这个问题,这个问题很可能与 Windows 最大路径限制有关:

Naming Files, Paths, and Namespaces, Maximum Path Length Limitation

命名文件、路径和命名空间最大路径长度限制

回答by David Ford

In my case the issue was that I'd manually deleted a non-compilation file which was marked as "missing". Once I deleted the reference to the now-missing file and recompiled - all was well.

就我而言,问题是我手动删除了一个标记为“丢失”的非编译文件。一旦我删除了对现在丢失的文件的引用并重新编译 - 一切都很好。

回答by corvuscorax

This can still happen in newer versions of Visual Studio (I just had it happen on Visual Studio 2013):

这在较新版本的 Visual Studio 中仍然可能发生(我刚刚在 Visual Studio 2013 上发生过):

Another thing to try is to close Visual Studio and delete the .suofile that is next to the .slnfile. (It will be re-generated the next time you Save all(or exit Visual Studio)).

要尝试的另一件事是关闭 Visual Studio 并删除该.suo文件旁边的.sln文件。(它将在您下次Save all(或退出 Visual Studio)时重新生成)。

I've had this problem when adding new projects to the solution on another machine and then pulling the revisions in, but the .suofile can be corrupted in other cases as well and lead to very strange Visual Studio behaviour, so deleting it is one of the things I always try.

我在另一台机器上向解决方案添加新项目然后拉入修订时遇到了这个问题,但.suo在其他情况下文件也可能被损坏并导致非常奇怪的 Visual Studio 行为,因此删除它是其中之一我总是尝试的东西。

Note that deleting the .suofile will reset the startup project(s) of the solution.

请注意,删除.suo文件将重置解决方案的启动项目。

More on the .suofile is here.

有关该.suo文件的更多信息,请点击此处

回答by Vikram

Well, my answer is not just the summary of all the solutions, but it offers more than that.

好吧,我的回答不仅仅是所有解决方案的总结,但它提供的不仅仅是这些。

Section (1):

第 (1) 节:

In general solutions:

一般解决方案:

I had four errors of this kind (‘metadata file could not be found') along with one error saying 'Source File Could Not Be Opened (‘Unspecified error ‘)'.

我有四个此类错误(“找不到元数据文件”),还有一个错误提示“无法打开源文件(“未指定错误”)。

I tried to get rid of ‘metadata file could not be found' error. For that, I read many posts, blogs, etc. and found these solutions may be effective (summarizing them over here):

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

  1. Restart Visual Studio and try building again.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  1. 重新启动 Visual Studio 并再次尝试构建。

  2. 转到“解决方案资源管理器”。右键单击解决方案。转到属性。转到“配置管理器”。检查“构建”下的复选框是否被选中。如果其中任何一个或全部未选中,请检查它们并再次尝试构建。

  3. 如果上述解决方案不起作用,则按照上面步骤 2 中提到的顺序,即使选中了所有复选框,也取消选中它们,再次检查并再次尝试构建。

  4. 构建顺序和项目依赖项:

    转到“解决方案资源管理器”。右键单击解决方案。转到“项目依赖项...”。您将看到两个选项卡:'Dependencies''Build Order'。此构建顺序是构建解决方案的顺序。检查项目依赖项和构建顺序,以验证依赖于其他项目(比如“project2”)的某个项目(比如“project1”)是否在该项目(比如“project2”)之前尝试构建。这可能是导致错误的原因。

  5. 检查丢失的 .dll 的路径:

    检查丢失的 .dll 的路径。如果路径包含空格或任何其他无效的路径字符,请将其删除并再次尝试构建。

    如果这是原因,则调整构建顺序。



Section (2):

第 (2) 节:

My particular case:

我的特殊情况:

I tried all the steps above with various permutations and combinations with restarting Visual Studio a few times. But, it did not help me.

我通过重新启动 Visual Studio 几次尝试了上述所有步骤,并进行了各种排列和组合。但是,它对我没有帮助。

So, I decided to get rid of other error I was coming across ('Source File Could Not Be Opened (‘Unspecified error ‘)').

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

I came across a blog post: TFS Error–Source File Could Not Be Opened (‘Unspecified error ‘)

我看到了一篇博文:TFS 错误——无法打开源文件('未指定的错误')

I tried the steps mentioned in that blog post, and I got rid of the error 'Source File Could Not Be Opened (‘Unspecified error ‘)'and surprisingly I got rid of other errors (‘metadata file could not be found')as well.

我尝试了该博客文章中提到的步骤,并且摆脱了错误“无法打开源文件(‘未指定的错误’)’,令人惊讶的是我摆脱了其他错误(‘找不到元数据文件’)作为好。



Section (3):

第 (3) 节:

Moral of the story:

故事的道德启示:

Try all solutions as mentioned in section (1) above (and any other solutions) for getting rid of the error. If nothing works out, as per the blog mentioned in section (2) above, delete the entries of all source files which are no longer present in the source control and the file system from your .csproj file.

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

回答by wtjones

I had this issue because .nuget\NuGet.exewas not included in my repository. Although I enabled DownloadNuGetExein NuGet.targets, it reported a proxy error when trying to download it. This caused the rest of the project builds to fail.

我有这个问题,因为.nuget\NuGet.exe它没有包含在我的存储库中。尽管我DownloadNuGetExe在 NuGet.targets 中启用了它,但在尝试下载它时报告了代理错误。这导致项目构建的其余部分失败。

回答by Baglay Vyacheslav

For me the following steps worked:

对我来说,以下步骤有效:

  • Find the project that is not building
  • Remove/add references to projects within the solution.
  • 查找未构建的项目
  • 删除/添加对解决方案中项目的引用。