生成项目时找不到元数据文件... 错误

每次启动 VisualStudio2008,第一次尝试运行项目时,都会得到错误 CS0006元数据文件... 无法找到。如果我重新构建完整的解决方案,它会工作。

关于解决方案的一些信息:

  • 我正在构建调试模式,VisualStudio 抱怨在发布文件夹中找不到 dll: s。

  • VisualStudio 抱怨的项目被解决方案中的许多其他项目使用。

  • 我已经将所有项目的默认输出路径分别更改为... ... build debug ProjectName 和... ... build release ProjectName。(只需要将所有构建文件放在一个目录中)

  • 我对另一个解决方案也有同样的问题。

  • 解决方案是从头开始创建的。

  • 解决方案中有9个项目,一个 WPF 和8个使用 dotnet 3.5的类库。

知道是什么导致了这个问题吗?

88981 次浏览

I had this issue, not sure if it will help but mine was caused by having two different versions of the same project referenced by two different solutions. When I built the solution with the reference to the correct project first the second solution would build fine, however, if I cleaned the first solution and tried to build the second solution it would fail with these dll reference error messages.

The solution for me was figuring out I had two projects with the same name which had been accidentally duplicated and removing the reference to the old incorrect project and adding a reference to the new one.

In any case it seems that these messages are a bit of a red herring, I would check your build output and find the first project that fails to build and very carefully check the references on that project.

i had the similar issue where "metadata could not be found". on the solution property, make sure that the "build" check box is marked in Build/Configuration Manager for each project.

Same thing happened. I have several solutions referencing the same library projects (.net 3.5). I noticed when one was built in debug/normal config, and another using some other compiler directive (sqlite/local mode), this would happen. Simply get both projects building with the same directives and you should be fine.

This is usually caused by a project that is referenced in a different solution than the one that is throwing the error. If you clean the other solution, or branch the code, you will more than likely see this error. The solution is to scroll down your list of "metadata not found" errors, and look at the references to the projects. 9/10 times, you will see a broken reference to a project that is not in this solution. Add the projects to fix the reference errors, and rebuild. That should fix it.

(I just ran into this today, and have in the past, and this has ALWAYS worked)

The way I've got round this in the past in VS2005 as well as just now in VS2008 is to make sure all of the dependancies are correct and the references are pointing to the projects not the dlls. Then go through and manually build each project in dependancy order. Once the last one builds you can run a full solution build and its fine.

This answer is for future reference for others as I know the question is over 15 months old.

Cheers

If you've add a new project to the solution, check that this is in the build list (see the Configuration Manager)

I got stuck with the save issue when I wanted to include a dll file generated by Matlab. And I finally solved it by copy a .ctf file, which means certificate I suppose, and a .netmodule, which is needed for proper operation of the .dll, along with the .dll file. And that actually worked! So, my suggestion is to check if the .dll needs any other files to get along with.

I have a couple of points I would like to make.

If you are relying on the solution file as your build file under MSBuild, ensure that you add projects to the solution file in the order in which you want them to build, i.e., based on the mutual dependency order of the projects. This becomes very important if you have projects in the solution that other projects depend upon, but the references have been added as "References" rather than as "Project References".

You should avoid that like the plague, but in case you do need to do that, then at least make sure the dependent projects appear earlier in the solution file.

You should bear in mind that the way Visual Studio generates build order is not exactly the same as the way MSBuild does it. This is because MSBuild primarily depends on the project file to tell it what the dependencies are, whereas Visual Studio can also save them in the soltuion file. Therefore, you can sometimes see situations where Visual Studio builds the solution perfectly, but MSBuild just can't do it.

I have had a couple of instances where I had to hand tweak the order in which the projects appear in the solution file as well as the order in which the projects were listed in the ProjectReferences element in a Web Site project in the solution file.

I hope the above information helps.

Windows 7 Ultimate 32 Visual Studio 2008 SQL Server v2005

I was receiving the same error. And I decided to remove and re-add the project references. I was unable to add them back because the Database reference in each of the referenced projects was blank.

Once I reset the database reference to the correct setting, I was able to build without further issue. Additionally, this was my first attempt to rebuild this project after having branched source code in VSS.

Good Luck

If you use LinqtoSQL Data contexts, for instance, and the .designer.cs file is missing, you will get the Metadata file could not be found error.

Recreating the designer.cs file is easy.

Open up the dbml using xml view. Add a blank line, then remove it, then save. That should regenerate your designer.cs file.

Under some circumstances, if you have code inside your data context's code-behind, this work around will not work. In this case, take the code out of the code behind and put it in notepad or something. Do the trick of adding then removing a line from the DC and save. Now put the code back and save.

I also experienced this error and the cause was that the Project is referencing to itself. I have no idea how it happened but I just removed the reference and voila

Another thing to verify is the path length... that causes also Metadata File not found and compilation errors... I just renamed my folders to shorter paths and voilá, classes that weren´t recognized and stayed black, turned blue just by renaming the folder.

For me I had a project referenced in another project. It didn't show it was broken in the references list in the solution explorer window but I removed and readded it anyway. It builds just fine now!

I have a similar problem each time I update the project from SVN.
Another solution for ASP.NET:

  1. Close the IDE.
  2. Delete the files in C:\WINDOWS\microsoft.net\framework\v…\Temporary ASP.NET File\.

I went through all these steps in VS2012, but I kept running into this issue when building the solution as a whole (the individual projects built just fine with no errors).

I found that if you right-click on your Solution in the Solution Explorer and select "Build Order" you can see the order that VS is using to rebuild your solution. It's likely out of whack.

You can correct the build order by clicking on the Dependencies tab and selecting the projects that depends on other projects in the solution and checking the projects they depend on. Once you hit okay and do a rebuild of the solution, you should be good to go.

In my case, I found out that one of my solution was referencing something that wasn't there on the computer (VBIDE). Once i removed the offending reference, the rest of the projects built correctly. Hope that helps someone.

And in another situation, I moved some code from one project to another, and that piece of code was referencing Json.net. I manually added a reference to Json.net but that made the problem come about it. I solved it by installing Json.net through NuGet and that made the problem go away. Hope that helps someone.

I had this error it was caused by one of my project dependencies where the assembly name had been changed in the project, but the reference was not updated. So updating the reference or renaming the assembly back will fix it.

EE - In My case the problem was in the project which has the Entity framework, open the diagram drag any table 2 cm :) and save, the VS will update all his links to the DB ...build this projects and build the solution, Buildssss.

The only thing that fixed me (because I'm not running VS2010 on an administrator account) is to manually move the environment variable VS120COMNTOOLS from System Variables to User Variables.

First make sure that the "build" check box is marked in Build -> Configuration Manager for each project.

In case, if you already have all projects selected under Build -> Configuration Manager menu, and restarting VS trick doesn't work for you either than you have to find the reference of the file(s) (could be dll or cs) in your project and delete those references manually. Those file(s)/reference(s) should be displayed with yellow icon. The error definitely guides you which project of solution you should be looking into.

The reason of this error is because you have deleted file(s) manually in windows explorer and VS hasn't updated the reference and trying to locate the file which doesn't exist anymore!

Deleting the entries of all source files which are no longer present in the source control and the file system from your .csproj file worked for me.


Detailed approach:

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

Section (1):

In general solutions:

I had 4 errors of this kind (‘metadata file could not be found’) along with 1 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 VS 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 2 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.


Section (2):

My particular case:

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

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: http://www.anujvarma.com/tfs-errorsource-file-could-not-be-opened-unspecified-error/#comment-1539

I tried the steps mentioned in that blog 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):

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.