2 // ResolveAssemblyReferenceTest.cs
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2006 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections;
31 using Microsoft.Build.BuildEngine;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Tasks;
34 using Microsoft.Build.Utilities;
35 using NUnit.Framework;
37 namespace MonoTests.Microsoft.Build.Tasks {
40 public class ResolveAssemblyReferenceTest {
47 public void TestGac1 ()
49 engine = new Engine (Consts.BinPath);
50 project = engine.CreateNewProject ();
51 project.LoadXml (ResolveAssembly ("System", null));
53 Assert.IsTrue (project.Build ("A"), "A1");
54 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
55 Assert.AreEqual (1, big.Count, "A2");
56 Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
60 public void TestHintPath1 ()
62 engine = new Engine (Consts.BinPath);
63 project = engine.CreateNewProject ();
64 project.LoadXml (ResolveAssembly (null, @"Test\resources\test.dll"));
66 Assert.IsTrue (project.Build ("A"), "A1");
67 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
68 Assert.AreEqual (1, big.Count, "A2");
69 Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
72 [Test, Category("NotWorking")]
73 public void ResolveBinary_FancyStuff ()
75 engine = new Engine (Consts.BinPath);
76 project = engine.CreateNewProject ();
77 project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\FancyStuff.dll"));
79 Assert.IsTrue (project.Build ("A"), "A1");
80 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
81 Assert.AreEqual (1, big.Count, "A2");
82 Assert.IsTrue (big[0].Include.EndsWith ("FancyStuff.dll"), "A3");
84 big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
85 Assert.AreEqual (1, big.Count, "A4");
86 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
89 [Test, Category("NotWorking")]
90 public void ResolveBinary_SimpleWrite ()
92 engine = new Engine (Consts.BinPath);
93 project = engine.CreateNewProject ();
94 project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\SimpleWrite.dll"));
96 Assert.IsTrue (project.Build ("A"), "A1");
97 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
98 Assert.AreEqual (1, big.Count, "A2");
99 Assert.IsTrue (big[0].Include.EndsWith ("SimpleWrite.dll"), "A3");
101 big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
102 Assert.AreEqual (0, big.Count, "A4");
105 [Test, Category("NotWorking")]
106 public void ResolveBinary_Testing ()
108 engine = new Engine (Consts.BinPath);
109 project = engine.CreateNewProject ();
110 project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\Testing.dll"));
112 Assert.IsTrue (project.Build ("A"), "A1");
113 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
114 Assert.AreEqual (1, big.Count, "A2");
115 Assert.IsTrue (big[0].Include.EndsWith ("Testing.dll"), "A3");
117 big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
118 Assert.AreEqual (0, big.Count, "A4");
121 [Test, Category("NotWorking")]
122 public void ResolveBinary_XbuildReferenceBugTest ()
124 engine = new Engine (Consts.BinPath);
125 project = engine.CreateNewProject ();
126 project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\XbuildReferenceBugTest.exe"));
128 Assert.IsTrue (project.Build ("A"), "A1");
129 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
130 Assert.AreEqual (1, big.Count, "A2");
131 Assert.IsTrue (big[0].Include.EndsWith ("XbuildReferenceBugTest.exe"), "A3");
133 big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
134 Assert.AreEqual (3, big.Count, "A4");
135 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
136 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("FancyStuff.dll")), "A6");
137 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("Testing.dll")), "A7");
140 [Test, Category("NotWorking")]
141 public void ResolveBinary_FancyStuffAndXbuild ()
143 engine = new Engine (Consts.BinPath);
144 project = engine.CreateNewProject ();
145 project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\FancyStuff.dll", @"Test\resources\binary\XbuildReferenceBugTest.exe"));
147 Assert.IsTrue (project.Build ("A"), "A1");
148 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
149 Assert.AreEqual (2, big.Count, "A2");
150 Assert.IsTrue (big[0].Include.EndsWith ("FancyStuff.dll"), "A3");
151 Assert.IsTrue (big[1].Include.EndsWith ("XbuildReferenceBugTest.exe"), "A3");
153 big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
154 Assert.AreEqual (2, big.Count, "A4");
155 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
156 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("Testing.dll")), "A6");
159 [Test, Category("NotWorking")]
160 public void ResolveBinary_SameAssemblyTwice ()
162 engine = new Engine (Consts.BinPath);
163 project = engine.CreateNewProject ();
164 project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\XbuildReferenceBugTest.exe", @"Test\resources\binary\XbuildReferenceBugTest2.exe"));
166 Assert.IsTrue (project.Build ("A"), "A1");
167 big = project.GetEvaluatedItemsByName ("ResolvedFiles");
168 Assert.AreEqual (2, big.Count, "A2");
169 Assert.IsTrue (big[0].Include.EndsWith ("XbuildReferenceBugTest.exe"), "A3");
170 Assert.IsTrue (big[1].Include.EndsWith ("XbuildReferenceBugTest2.exe"), "A3b");
172 big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
173 Assert.AreEqual (3, big.Count, "A4");
174 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
175 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("FancyStuff.dll")), "A6");
176 Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("Testing.dll")), "A7");
179 string ResolveAssembly (string gacAssembly, params string[] hintPaths)
181 string reference = "";
182 if (string.IsNullOrEmpty (gacAssembly)) {
183 foreach (var hintPath in hintPaths) {
184 reference += string.Format (
185 @"<Reference Include='{0}'>
186 <HintPath>{1}</HintPath>
187 </Reference>", System.IO.Path.GetFileNameWithoutExtension (hintPath), hintPath);
190 reference += string.Format (
191 @"<Reference Include='{0}'/>", gacAssembly);
195 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
201 {CandidateAssemblyFiles};
204 {TargetFrameworkDirectory};
212 <ResolveAssemblyReference
213 Assemblies='@(Reference)'
214 SearchPaths='$(SearchPaths)'
216 <Output TaskParameter='ResolvedFiles' ItemName='ResolvedFiles'/>
217 <Output TaskParameter='ResolvedDependencyFiles' ItemName='ResolvedDependencyFiles'/>
218 </ResolveAssemblyReference>