protected override void ResolveReference() { if (this.ProjectMgr == null || this.ProjectMgr.IsClosed) { return; } MSBuild.BuildItemGroup group = this.ProjectMgr.BuildProject.GetEvaluatedItemsByName(ProjectFileConstants.ReferencePath); if (group != null) { IEnumerator enumerator = group.GetEnumerator(); while (enumerator.MoveNext()) { MSBuild.BuildItem item = (MSBuild.BuildItem)enumerator.Current; string fullPath = this.GetFullPathFromPath(item.FinalItemSpec); System.Reflection.AssemblyName name = System.Reflection.AssemblyName.GetAssemblyName(fullPath); // Try with full assembly name and then with weak assembly name. if (String.Compare(name.FullName, this.assemblyName.FullName, StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(name.Name, this.assemblyName.Name, StringComparison.OrdinalIgnoreCase) == 0) { // set the full path now. this.assemblyPath = fullPath; this.resolvedAssemblyName = name; // No hint path is needed since the assembly path will always be resolved. return; } } } }
/// <summary> /// Does the actual job of resolving an assembly reference. We need a private method that does not violate /// calling virtual method from the constructor. /// </summary> private void ResolveAssemblyReference() { if (this.ProjectMgr == null || this.ProjectMgr.IsClosed || !this.ProjectMgr.HasPassedSecurityChecks) { return; } MSBuild.BuildItemGroup group = this.ProjectMgr.BuildProject.GetEvaluatedItemsByName(ProjectFileConstants.ReferencePath); if (group != null) { IEnumerator enumerator = group.GetEnumerator(); while (enumerator.MoveNext()) { MSBuild.BuildItem item = (MSBuild.BuildItem)enumerator.Current; string fullPath = this.GetFullPathFromPath(item.FinalItemSpec); System.Reflection.AssemblyName name = System.Reflection.AssemblyName.GetAssemblyName(fullPath); // Try with full assembly name and then with weak assembly name. if (String.Compare(name.FullName, this.assemblyName.FullName, StringComparison.OrdinalIgnoreCase) == 0 || String.Compare(name.Name, this.assemblyName.Name, StringComparison.OrdinalIgnoreCase) == 0) { if (!NativeMethods.IsSamePath(fullPath, this.assemblyPath)) { // set the full path now. this.assemblyPath = fullPath; // We have a new item to listen too, since the assembly reference is resolved from a different place. this.fileChangeListener.ObserveItem(this.assemblyPath); } this.resolvedAssemblyName = name; // No hint path is needed since the assembly path will always be resolved. return; } } } }
public void TestGetEnumerator () { BuildItemGroup big = new BuildItemGroup (); big.AddNewItem ("a", "c"); big.AddNewItem ("b", "d"); IEnumerator e = big.GetEnumerator (); e.MoveNext (); Assert.AreEqual ("a", ((BuildItem) e.Current).Name, "A1"); Assert.AreEqual ("c", ((BuildItem) e.Current).FinalItemSpec, "A2"); e.MoveNext (); Assert.AreEqual ("b", ((BuildItem) e.Current).Name, "A3"); Assert.AreEqual ("d", ((BuildItem) e.Current).FinalItemSpec, "A4"); Assert.IsFalse (e.MoveNext ()); }