Mono xbuild:将调试符号从 NuGet 包文件夹复制到输出 bin 文件夹

Mono xbuild: Copy debug symbols from NuGet packages folder into output bin folder

使用包含符号的 NuGet 包时,Visual Studio 会将这些调试符号文件 (*.pdb) 直接复制到 bin 输出文件夹中。

在 Linux 上使用 Mono 使用 NuGet 和 xbuild 时不会发生这种情况 - pdb 文件不会复制到输出文件夹。

有没有办法让 xbuild 模仿 Visual Studio 的 pdb 复制行为?

现在我可以通过编写这个脚本来实现我想要的,它还将 pdb 文件转换为 mdb(需要 pdb2mdb 在路径中):

#!/bin/bash

PACKAGE_PATH_SUBSTR=
CSPROJ=
OUT_DIR=

# 1.) search for file references in the .csproj file with the help of the partial nuget package path name
# 2.) replace .dll with .pdb
# 3.) replace all left <HintPath> and </HintPath> tags
# 4.) replace windows path separators (\) with unix ones (/)
PDB_CANDIDATES=$(grep -oP '<HintPath>(.*'${PACKAGE_PATH_SUBSTR}'.*\.dll)</HintPath>' $CSPROJ | sed -e "s/\.dll/\.pdb/g" | sed -e 's/<\(\/\)\{0,1\}HintPath>//g' | sed -e 's/\/\//g' )

# loop through all possibly existent pdb file names
for item in ${PDB_CANDIDATES}; do
        # check if the pdb file candidate really exists
        if [ -e $item ]; then
                # pdb exists, copy it to the bin output path
                cp -v ${item} ${OUT_DIR}
                # convert pdb to mdb
                pdb2mdb ${OUT_DIR}/$(basename $(echo $item | sed -e 's/\.pdb/.dll/g') )
                # if you wanted you could delete the pdb file now.
        fi
done

用法: copy_pdb_from_nuget.sh packages MyProject.csproj ./bin