public void LoadFrom (FilePath assemblyPath)
{
FileName = assemblyPath;
var tid = Runtime.SystemAssemblyService.GetTargetFrameworkForAssembly (Runtime.SystemAssemblyService.DefaultRuntime, assemblyPath);
if (tid != null)
targetFramework = Runtime.SystemAssemblyService.GetTargetFramework (tid);
AssemblyDefinition adef = AssemblyDefinition.ReadAssembly (assemblyPath);
MdbReaderProvider mdbProvider = new MdbReaderProvider ();
try {
ISymbolReader reader = mdbProvider.GetSymbolReader (adef.MainModule, assemblyPath);
adef.MainModule.ReadSymbols (reader);
} catch {
// Ignore
}
var files = new HashSet<FilePath> ();
foreach (TypeDefinition type in adef.MainModule.Types) {
foreach (MethodDefinition met in type.Methods) {
if (met.HasBody && met.Body.Instructions != null && met.Body.Instructions.Count > 0) {
SequencePoint sp = met.Body.Instructions[0].SequencePoint;
if (sp != null)
files.Add (sp.Document.Url);
}
}
}
FilePath rootPath = FilePath.Empty;
foreach (FilePath file in files) {
AddFile (file, BuildAction.Compile);
if (rootPath.IsNullOrEmpty)
rootPath = file.ParentDirectory;
else if (!file.IsChildPathOf (rootPath))
rootPath = FindCommonRoot (rootPath, file);
}
if (!rootPath.IsNullOrEmpty)
BaseDirectory = rootPath;
/*
foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences) {
if (aref.Name == "mscorlib")
continue;
string asm = assemblyPath.ParentDirectory.Combine (aref.Name);
if (File.Exists (asm + ".dll"))
References.Add (new ProjectReference (ReferenceType.Assembly, asm + ".dll"));
else if (File.Exists (asm + ".exe"))
References.Add (new ProjectReference (ReferenceType.Assembly, asm + ".exe"));
else
References.Add (new ProjectReference (ReferenceType.Package, aref.FullName));
}*/
}