private void Load() { var projectPath = LocalPath; var projectDir = Path.GetDirectoryName(projectPath); var splitOptions = StringSplitOptions.RemoveEmptyEntries; var setupInformation = AppDomain.CurrentDomain.SetupInformation; // Always null, why? probing path is set in vvvv.exe.config // var searchPath = AppDomain.CurrentDomain.RelativeSearchPath; ReferencePaths = new List <string>() { Path.GetFullPath(Path.Combine(setupInformation.ApplicationBase, "lib", "core")), Path.GetFullPath(Path.Combine(setupInformation.ApplicationBase, "lib", "nodes", "plugins")) }; try { var msBuildProject = MsProject; var referencePathProperty = msBuildProject.GetPropertyValue("ReferencePath"); if (!string.IsNullOrEmpty(referencePathProperty)) { foreach (var refPath in referencePathProperty.Split(FSplitChars, splitOptions)) { var trimmedRefPath = refPath.Trim(); trimmedRefPath = refPath.TrimEnd(Path.DirectorySeparatorChar); var absoluteRefPath = Path.IsPathRooted(trimmedRefPath) ? trimmedRefPath : Path.Combine(projectDir, trimmedRefPath); try { absoluteRefPath = Path.GetFullPath(absoluteRefPath); if (!ReferencePaths.Contains(absoluteRefPath) && Directory.Exists(absoluteRefPath)) { ReferencePaths.Add(absoluteRefPath); } } catch (NotSupportedException) { // Ignore } } } // Iterate through the various itemgroups // and subsequently through the items foreach (var projectItem in msBuildProject.Items) { switch (projectItem.ItemType) { case "Reference": IReference reference = null; var include = projectItem.EvaluatedInclude; if (include == "System.ComponentModel.Composition") { include = "System.ComponentModel.Composition.Codeplex"; } if (projectItem.HasMetadata("HintPath")) { var hintPath = projectItem.GetMetadataValue("HintPath"); var assemblyLocation = hintPath; if (!Path.IsPathRooted(assemblyLocation)) { assemblyLocation = projectDir.ConcatPath(hintPath); } if (!File.Exists(assemblyLocation)) { //search in reference paths assemblyLocation = TryAddReferencePath(assemblyLocation, include); } if (File.Exists(assemblyLocation)) { assemblyLocation = Path.GetFullPath(assemblyLocation); } reference = new AssemblyReference(assemblyLocation); } else { var assemblyLocation = TryAddReferencePath("", include); if (File.Exists(assemblyLocation)) { reference = new AssemblyReference(assemblyLocation, true); } } // Reference couldn't be found, try GAC if (reference == null) { try { var assemblyLocation = AssemblyCache.QueryAssemblyInfo(include); reference = new AssemblyReference(assemblyLocation, true); } catch (Exception) { reference = new AssemblyReference(string.Format("{0}.dll", include), true); } } if (reference != null) { References.Add(reference); } break; case "ProjectReference": // TODO: Load project references. break; case "Compile": case "None": IDocument document = null; var canBeCompiled = projectItem.ItemType == "Compile"; var documentPath = projectDir.ConcatPath(projectItem.EvaluatedInclude); if (!File.Exists(documentPath)) { document = new MissingDocument(documentPath, documentPath, canBeCompiled); } else { FDocumentConverter.Convert(documentPath, out document); } if (document != null) { Documents.Add(document); } break; default: break; } } } catch (Exception e) { Shell.Instance.Logger.Log(e); } }
protected override void DoLoad() { var projectPath = Location.LocalPath; var projectDir = Path.GetDirectoryName(projectPath); var msBuildProject = new MsBuild.Project(); msBuildProject.Load(projectPath); var splitChars = new char[] { ';' }; var splitOptions = StringSplitOptions.RemoveEmptyEntries; var setupInformation = AppDomain.CurrentDomain.SetupInformation; // Always null, why? probing path is set in vvvv.exe.config // var searchPath = AppDomain.CurrentDomain.RelativeSearchPath; ReferencePaths = new List <string>() { Path.Combine(setupInformation.ApplicationBase, "lib", "core") }; var referencePathProperty = msBuildProject.GetEvaluatedProperty("ReferencePath"); if (!string.IsNullOrEmpty(referencePathProperty)) { foreach (var refPath in referencePathProperty.Split(splitChars, splitOptions)) { if (!ReferencePaths.Contains(refPath.Trim())) { ReferencePaths.Add(refPath); } } } // Iterate through the various itemgroups // and subsequently through the items foreach (MsBuild.BuildItemGroup itemGroup in msBuildProject.ItemGroups) { foreach (MsBuild.BuildItem item in itemGroup) { switch (item.Name) { case "Reference": IReference reference = null; if (item.Include == "System.ComponentModel.Composition") { item.Include = "System.ComponentModel.Composition.Codeplex"; } if (item.HasMetadata("HintPath")) { var hintPath = item.GetEvaluatedMetadata("HintPath"); var assemblyLocation = hintPath; if (!Path.IsPathRooted(assemblyLocation)) { assemblyLocation = projectDir.ConcatPath(hintPath); } if (!File.Exists(assemblyLocation)) { //search in reference paths assemblyLocation = TryAddReferencePath(assemblyLocation, item.Include); } if (File.Exists(assemblyLocation)) { assemblyLocation = Path.GetFullPath(assemblyLocation); } reference = new AssemblyReference(assemblyLocation); } else { var assemblyLocation = TryAddReferencePath("", item.Include); if (File.Exists(assemblyLocation)) { reference = new AssemblyReference(assemblyLocation, true); } } // Reference couldn't be found, try GAC if (reference == null) { try { var assemblyLocation = AssemblyCache.QueryAssemblyInfo(item.Include); reference = new AssemblyReference(assemblyLocation, true); } catch (Exception) { reference = new AssemblyReference(string.Format("{0}.dll", item.Include), true); } } if (reference != null) { References.Add(reference); } break; case "ProjectReference": // TODO: Load project references. break; case "Compile": case "None": IDocument document; if (FDocumentConverter.Convert(projectDir.ConcatPath(item.Include), out document)) { Documents.Add(document); document.Load(); } break; default: break; } } } base.DoLoad(); }