[Microsoft.Build.Tasks] Don't throw if duplicate dependencies are found
authorAlan McGovern <alan@xamarin.com>
Thu, 30 Aug 2012 00:22:23 +0000 (01:22 +0100)
committerAlan McGovern <alan@xamarin.com>
Thu, 30 Aug 2012 00:22:23 +0000 (01:22 +0100)
We should use the dictionary setter instead of the Add method so that
we do not get an exception if the same Nth order dependency is found
multiple times

mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/ResolveAssemblyReference.cs
mcs/class/Microsoft.Build.Tasks/Test/Microsoft.Build.Tasks/ResolveAssemblyReferenceTest.cs
mcs/class/Microsoft.Build.Tasks/Test/resources/binary/XbuildReferenceBugTest2.exe [new file with mode: 0755]

index 0265415a4364d43a6a38672c358695d6d288bd1f..e9a26a444eb3d8951d944d8213c99a244ff4f8e5 100644 (file)
@@ -338,7 +338,7 @@ namespace Microsoft.Build.Tasks {
 
                                        if (resolved_ref != null && !IsFromGacOrTargetFramework (resolved_ref)
                                                        && resolved_ref.FoundInSearchPath != SearchPath.PkgConfig) {
-                                               tempResolvedDepFiles.Add (resolved_ref.AssemblyName.FullName, resolved_ref.TaskItem);
+                                               tempResolvedDepFiles[resolved_ref.AssemblyName.FullName] = resolved_ref.TaskItem;
                                                dependencies.Enqueue (resolved_ref.TaskItem.ItemSpec);
                                        }
                                }
index 0cd3e79d6a7aab46a1479bd21041aba843a433b9..5816d7adf5ccb09c891470760f3a6fd01e05b3c1 100644 (file)
@@ -136,17 +136,58 @@ namespace MonoTests.Microsoft.Build.Tasks {
                        Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("FancyStuff.dll")), "A6");
                        Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("Testing.dll")), "A7");
                }
-               
-               string ResolveAssembly (string gacAssembly, string hintPath)
+
+               [Test]
+               public void ResolveBinary_FancyStuffAndXbuild ()
+               {
+                       engine = new Engine (Consts.BinPath);
+                       project = engine.CreateNewProject ();
+                       project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\FancyStuff.dll", @"Test\resources\binary\XbuildReferenceBugTest.exe"));
+                       
+                       Assert.IsTrue (project.Build ("A"), "A1");
+                       big = project.GetEvaluatedItemsByName ("ResolvedFiles");
+                       Assert.AreEqual (2, big.Count, "A2");
+                       Assert.IsTrue (big[0].Include.EndsWith ("FancyStuff.dll"), "A3");
+                       Assert.IsTrue (big[1].Include.EndsWith ("XbuildReferenceBugTest.exe"), "A3");
+                       
+                       big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
+                       Assert.AreEqual (2, big.Count, "A4");
+                       Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
+                       Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("Testing.dll")), "A6");
+               }
+
+               [Test]
+               public void ResolveBinary_SameAssemblyTwice ()
+               {
+                       engine = new Engine (Consts.BinPath);
+                       project = engine.CreateNewProject ();
+                       project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\XbuildReferenceBugTest.exe", @"Test\resources\binary\XbuildReferenceBugTest2.exe"));
+
+                       Assert.IsTrue (project.Build ("A"), "A1");
+                       big = project.GetEvaluatedItemsByName ("ResolvedFiles");
+                       Assert.AreEqual (2, big.Count, "A2");
+                       Assert.IsTrue (big[0].Include.EndsWith ("XbuildReferenceBugTest.exe"), "A3");
+                       Assert.IsTrue (big[1].Include.EndsWith ("XbuildReferenceBugTest2.exe"), "A3b");
+                       
+                       big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
+                       Assert.AreEqual (3, big.Count, "A4");
+                       Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
+                       Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("FancyStuff.dll")), "A6");
+                       Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("Testing.dll")), "A7");
+               }
+
+               string ResolveAssembly (string gacAssembly, params string[] hintPaths)
                {
-                       string reference;
+                       string reference = "";
                        if (string.IsNullOrEmpty (gacAssembly)) {
-                               reference = string.Format (
-                                       @"<Reference Include='{0}'>
-                                                       <HintPath>{1}</HintPath>
-                                               </Reference>", System.IO.Path.GetFileNameWithoutExtension (hintPath), hintPath);
+                               foreach (var hintPath in hintPaths) {
+                                       reference += string.Format (
+                                               @"<Reference Include='{0}'>
+                                                               <HintPath>{1}</HintPath>
+                                                       </Reference>", System.IO.Path.GetFileNameWithoutExtension (hintPath), hintPath);
+                               }
                        } else {
-                               reference = string.Format (
+                               reference += string.Format (
                                        @"<Reference Include='{0}'/>", gacAssembly);
                        }
                        
diff --git a/mcs/class/Microsoft.Build.Tasks/Test/resources/binary/XbuildReferenceBugTest2.exe b/mcs/class/Microsoft.Build.Tasks/Test/resources/binary/XbuildReferenceBugTest2.exe
new file mode 100755 (executable)
index 0000000..2f2d165
Binary files /dev/null and b/mcs/class/Microsoft.Build.Tasks/Test/resources/binary/XbuildReferenceBugTest2.exe differ