Is there a way to programmatically retrieve the URL from which Visual
Studio downloaded a file?
There should have no open API to achieve this, but meta file pdb should be able to achieve some information:
using System;
using System.IO;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
class Program
{
static void Main(string[] args)
{
string pdbPath = @"C:\Users\Administrator\Downloads\Newtonsoft.Json.pdb"; // Specify the path to your PDB file
string sourceLinkJson = GetSourceLinkJson(pdbPath);
if (sourceLinkJson != null)
{
Console.WriteLine("Source Link JSON:");
Console.WriteLine(sourceLinkJson);
}
else
{
Console.WriteLine("Source Link information not found.");
}
}
static string GetSourceLinkJson(string pdbPath)
{
// The well-known Guid for Source Link
Guid sourceLinkGuid = new Guid("CC110556-A091-4D38-9FEC-25AB9A351A6A");
using (FileStream stream = File.OpenRead(pdbPath))
using (MetadataReaderProvider metadataReaderProvider = MetadataReaderProvider.FromPortablePdbStream(stream))
{
MetadataReader metadataReader = metadataReaderProvider.GetMetadataReader();
foreach (var handle in metadataReader.CustomDebugInformation)
{
var cdi = metadataReader.GetCustomDebugInformation(handle);
var cdiKindGuid = metadataReader.GetGuid(cdi.Kind);
if (cdiKindGuid == sourceLinkGuid)
{
// If the kind matches the Source Link Guid, get the value
var value = metadataReader.GetBlobBytes(cdi.Value);
return System.Text.Encoding.UTF8.GetString(value);
}
}
}
return null;
}
}
Is it possible to determine the type of source control provider
(GitHub, GitLab, Bitbucket, etc.) based on the downloaded file's
content or metadata?
You can judge this based on the information contained in the URL.