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

时间:2015-12-08 16:09:45

标签: c# visual-studio mono nuget xbuild

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

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

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

1 个答案:

答案 0 :(得分:2)

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

#!/bin/bash

PACKAGE_PATH_SUBSTR=$1
CSPROJ=$2
OUT_DIR=$3

# 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