Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
[SharpCli] Remove patch for pdbs as we need to do it at deploy time f…
Browse files Browse the repository at this point in the history
…or nuget
  • Loading branch information
xoofx committed Feb 21, 2014
1 parent 651700c commit f6d5b67
Showing 1 changed file with 0 additions and 85 deletions.
85 changes: 0 additions & 85 deletions Source/Tools/SharpCli/InteropApp.cs
Expand Up @@ -736,88 +736,6 @@ static string ProgramFilesx86()
return Environment.GetEnvironmentVariable("ProgramFiles");
}

private static FieldInfo GetField(Type type, string name, ref FieldInfo fieldInfo)
{
return fieldInfo ?? (fieldInfo = type.GetField(name, BindingFlags.Instance | BindingFlags.NonPublic));
}

private static string MakeRelative(string basePath, string absolutePath)
{
if(absolutePath.StartsWith(".."))
return absolutePath;

try
{
Uri relativeUri = new Uri(basePath).MakeRelativeUri(new Uri(absolutePath));
return Uri.UnescapeDataString(relativeUri.ToString()).Replace('/', '\\');
}
catch(Exception ex)
{
// Just in case we are messing with absolute paths, leave it as it was in the pdb
return absolutePath;
}
}

/// <summary>
/// Patches the PDB to use relative path for source file instead of absolute path.
/// Having relative path is making the pdb much easier to redistribute (and we don't need anymore
/// to distribute pdb files to nuget symbols server)
/// </summary>
/// <param name="assembly">The assembly.</param>
private void PatchPdbToUseRelativePath(AssemblyDefinition assembly)
{
FieldInfo functionsField = null;
FieldInfo linesField = null;
FieldInfo fileField = null;
FieldInfo nameField = null;

foreach(var module in assembly.Modules)
{
ISymbolReader symbols = module.SymbolReader;
if(symbols == null)
continue;

var basePath = module.FullyQualifiedName;
if(basePath == null)
continue;
basePath = Path.GetDirectoryName(basePath);
if(basePath == null)
continue;
if(!basePath.EndsWith("\\"))
{
basePath += "\\";
}

// Because we don't have access to the underlying classes, we are doing this with reflection
var functions = (IDictionary)GetField(symbols.GetType(), "functions", ref functionsField).GetValue(symbols);

if(functions == null)
return;

foreach(var function in functions.Values)
{
var lines = (object[])GetField(function.GetType(), "lines", ref linesField).GetValue(function);
if(lines == null)
continue;

foreach(var line in lines)
{
var source = GetField(line.GetType(), "file", ref fileField).GetValue(line);
if(source == null)
continue;

GetField(source.GetType(), "name", ref nameField);
var name = (string)nameField.GetValue(source);
if(name == null)
continue;

var newName = MakeRelative(basePath, name);
nameField.SetValue(source, newName);
}
}
}
}

/// <summary>
/// Patches the file.
/// </summary>
Expand Down Expand Up @@ -852,9 +770,6 @@ public bool PatchFile(string file)
assembly = AssemblyDefinition.ReadAssembly(file, readerParameters);
((BaseAssemblyResolver)assembly.MainModule.AssemblyResolver).AddSearchDirectory(Path.GetDirectoryName(file));

// Patch pdb to use relative instead of absolute file path
PatchPdbToUseRelativePath(assembly);

foreach (var assemblyNameReference in assembly.MainModule.AssemblyReferences)
{
if (assemblyNameReference.Name.ToLower() == "mscorlib")
Expand Down

0 comments on commit f6d5b67

Please sign in to comment.