如何在不引用实际二进制文件的情况下获得项目引用

How to have a Project Reference without referencing the actual binary

以下工作正常,但它不会复制 Asp.net Core 2.0 项目的 .pdb 文件。

<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

那么,复制pdb文件应该怎么做呢?

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

正如 Marc 和 that bolg 指出的那样 这种方法在 Visual Studio 复制 .​​pdb 文件时不起作用。因为我们设置了<ReferenceOutputAssembly>false</ReferenceOutputAssembly>,项目引用没有引用实际的二进制文件,VS/MSBuild不会复制.pdb文件。

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.

如果您仍想复制此 .pdb 文件,可以为您的项目使用 MSBuild copy task or a build event

MSBuild复制任务:

为此,请卸载您的项目。然后在项目的最后,就在结束标记之前,放置在脚本下面:

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

构建事件:

在 Pre-build/Post-build 事件中添加以下构建命令行:

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

注意:不要忽略构建命令行中的双引号和空格。

希望对您有所帮助。