首页 > 解决方案 > 我可以在现有 PDB 文件上手动运行 SourceLink 吗?

问题描述

假设我从源代码构建了一个(C++ 或 .NET)库,所以我在本地有源代码和 PDB 文件,但我不想修改库代码以添加/SOURCELINKnuget 包

是否可以在命令行上运行 sourcelink 以将现有的 PDB 链接到 git 存储库?

标签: sourcelink

解决方案


如果您没有修改源代码,那么可以,但是您必须手动下载 .PDB 文件并将它们包含在您编译的输出文件夹中,然后使用符合以下模式的正确 .json 文件将其上传到 git:

JSON 配置文件包含本地文件路径到 URL 的简单映射,可以通过 http 或 https 检索源文件。调试器将从 PDB 检索当前位置的原始文件路径,在 Source Link 映射中查找此路径,并使用生成的 URL 下载源文件。

json文件的架构是:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "SourceLink",
    "description": "A mapping of source file paths to URLs",
    "type": "object",
    "properties": {
        "documents": {
            "type": "object",
            "minProperties": 1,
            "additionalProperties": {
                "type": "string"
            },
            "description": "Each document is defined by a file path and a URL. Original source file paths are compared 
                             case-insensitively to documents and the resulting URL is used to download source. The document 
                             may contain an asterisk to represent a wildcard in order to match anything in the asterisk's 
                             location. The rules for the asterisk are as follows:
                             1. The only acceptable wildcard is one and only one '*', which if present will be replaced by a relative path.
                             2. If the file path does not contain a *, the URL cannot contain a * and if the file path contains a * the URL must contain a *.
                             3. If the file path contains a *, it must be the final character.
                             4. If the URL contains a *, it may be anywhere in the URL."
        }
    },
    "required": ["documents"]
}

不幸的是,我没有找到用于创建这些文件的命令行实用程序,超出/SOURCELINK了原始帖子中不允许的范围。


推荐阅读