Search code examples
debuggingvisual-studio-2019intellisensesolutionpdb-files

Can I access source code sitting in a different solution in Visual studio (.net/C#)


I have solution A (which has the startup project) and solution B. Solution A uses things from solution B. For that A has a project which when rebuilt copies dlls and .pdbs to A's directories. Is there a way to make solution A recognize source code that sits in B? For example if I have a class moo in B, can I accomplish the following?

  1. Have Intellisense in solution A be aware of type moo and moo's methods, including recommending it when trying to instantiate a new object?
  2. Be able to F12 the moo type from solution A and have visual studio open the original source code for me just like types that originate from solution A?

Solution

  • Can I access source code sitting in a different solution in Visual studio (.net/C#)

    To debug the projects of Solution B in Solution A, you should make sure that you have xx.dll and xx.pdb files from Solution B are on the outputpath folder of Solution A.

    Just as Hans said, you can right-click on Solution A -->Add-->Existing Project-->select the related xxx.csproj of Solution B.

    After that, Click on References of the project from Solution A --> Add Reference--> Projects--> select the target imported project from Solution B.

    With them, you could debug that project and enter into B's code in Solution A.

    =================

    Besides, if the project of the solution B is a class library project, you could also use Add Reference node on the project of Solution A to reference the target xxx.dll.

    Right-click on the project-->Add Reference-->Browse-->find the output file xxx.dll of the Solution B in the new instance.

    Please note you should use Debug Configuration to build them all.

    Then you can use it in your project.

    In addition, you could also use ProjectReference xml node in xxx.csproj file of Solution A.

    Add these in xxx.csproj file:

    <ItemGroup>
            <ProjectReference Include="xxxx\SolutionB\xxxx.csproj">  // the path of the project in Solution B
                <Name>xxxxx</Name>  //name of the project           
            </ProjectReference>
    </ItemGroup>
    

    Then build your project once and then you can get it.

    Although there is a warning the referenced component xxx cannot be referenced, vs can still find the referenced project and use its content.