Metadata file … could not be found error when building projects

前端 未结 21 3045
北恋
北恋 2020-12-14 14:28

Every time I start Visual Studio 2008, the first time I try to run the project I get the error CS0006 The metadata file ... could not be found. If I do a rebuild of the comp

相关标签:
21条回答
  • 2020-12-14 14:46

    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.

    0 讨论(0)
  • 2020-12-14 14:49

    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.


    0 讨论(0)
  • 2020-12-14 14:50

    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.

    0 讨论(0)
  • 2020-12-14 14:51

    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.

    0 讨论(0)
  • 2020-12-14 14:51

    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.

    0 讨论(0)
  • 2020-12-14 14:52

    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.

    0 讨论(0)
提交回复
热议问题