Why can't I reference my class library?

后端 未结 20 1705
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 12:38

I have a solution that contains a website and a class library in Visual Studio 2008.

I then have another web site project outside of the solution that needs to refe

相关标签:
20条回答
  • 2020-12-08 13:10

    I had similar issue. What worked for me is that I had added wrong Class Library from visual studio. I added by using the search feature of visual studio.

    What I needed to do was Add New Project > Visual C# > Class Library. And this newly added class library is the right one and can now be added as reference to any project.

    0 讨论(0)
  • 2020-12-08 13:11

    I had a similar problem, will all my references being buggered up by Resharper - The solution which worked for me is to clear the Resharper Cache and then restarting VS

    tools->options->resharper->options-> general-> click the clear caches button and restart VS

    0 讨论(0)
  • 2020-12-08 13:11

    Since they are both in the same solution, instead of adding a reference to the DLL, add a reference to the class library project itself (the Add Reference dialog will have a tab for this).

    Ahh, it's a different solution. Missed that. How about you try instead of adding a reference to the project affffding a reference to the compiled DLL of your class library. The Add Reference dialog has a Browse tab which does this.

    0 讨论(0)
  • 2020-12-08 13:13

    I found how to fix this issue (for me at least). Why it worked, I'm not sure, but it did. (I just tried against a second website that was having the same problem and the following solution worked for that as well).

    I tried the normal cleaning of the projects and rebuilding, shutting down all my Visual Studio instances and restarting them, even tried restarting my computer.

    What actually worked was opening up the project in Visual Studio, closing all the open tabs, and then shutting it down.

    Before I had left the tabs open because I didn't think it mattered (and I hardly ever close the tabs I'm using).

    0 讨论(0)
  • 2020-12-08 13:17

    If you're referencing assemblies for projects that are in the same solution, add a Project reference (using the "Projects" tab) rather than browsing for the dll in the \bin\Debug (or \bin\Release) folder (using the "Browse" tab). See screen shot below. Only browse for the assembly/dll file if it's considered an external assembly.

    enter image description here

    0 讨论(0)
  • 2020-12-08 13:17

    I had a similar issue in VS 2010, when creating a test project for an MVC 2 application. The symptoms were identical.

    The message from ReSharper was somewhat misleading. For a moment I completely ignored ReSharper and did it the "manual VS way":

    1. I cleaned the solution.
    2. I manually added the reference to the MVC project.
    3. I manually added the using directives.
    4. ctrl-shift-b

    At this stage I got a compilation error: I should have referenced the System.Web.Mvc assembly in my test project (sigh). Adding this reference causes the project to compile. The ReSharper issues remain, but the ReSharper test runner works.

    When I restart VS, the ReSharper errors are gone too. I'm not sure if the restart is required - simply closing the .cs file might be enough.

    From now on, when I see the ReSharper message

    Failed to reference module. Probably, reference will produce circular dependencies between projects.

    I'll read

    Failed to reference module. Probably, reference will produce circular dependencies between projects, or you are missing some references to dependencies of the reference's dependencies.

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