Search code examples
c#visual-studiomsbuildasp.net-core-2.0debug-symbols

How to have a Project Reference without referencing the actual binary


Following works fine but it does not copy the .pdb file for Asp.net Core 2.0 project.

<ProjectReference Include="..\ProjectA\ProjectA.csproj">
    <Project>{b402782f-de0a-41fa-b364-60612a786fb2}</Project>
    <Name>ProjectA</Name>
    <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    <OutputItemType>Content</OutputItemType>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <Targets>Build;DebugSymbolsProjectOutputGroup</Targets>
</ProjectReference>

https://blogs.msdn.microsoft.com/kirillosenkov/2015/04/04/how-to-have-a-project-reference-without-referencing-the-actual-binary

So, what should we do for copying the pdb file?


Solution

  • So, what should we do for copying the pdb file?

    Just as Marc and that bolg pointed out this method not work in the Visual Studio to copy the .pdb file. Because we set <ReferenceOutputAssembly>false</ReferenceOutputAssembly>, the project reference without referencing the actual binary, VS/MSBuild will not copy the .pdb file.

    many people have asked how to also copy the .pdb file in addition to the .exe/.dll. Turns out there is a trick, but it doesn’t work when building in VS. But it’s OK since you don’t really need the .pdb in VS anyway, since the debugger will find the .pdb at its original path anyway.

    If you still want to copy this .pdb file, you can use MSBuild copy task or a build event for your project:

    MSBuild copy task:

    To accomplish this, unload your project. Then at the very end of the project, just before the end-tag , place below scripts:

    <Target Name="CopyPDBfile" AfterTargets="Build">
        <Copy SourceFiles="$(SolutionDir)ProjectA\bin\Debug\ProjectA.pdb" DestinationFolder="$(TargetDir)" />
    </Target>
    

    Build event:

    Add following build command line in the Pre-build/Post-build event:

    xcopy /y "$(SolutionDir)ProjectA\bin\Debug\ProjectA.pdb" "$(TargetDir)"
    

    Note: Do not ignore double quotes and spaces in the build command line.

    Hope this helps.