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");
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");
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");
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");
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 string ResolveAssembly (string gacAssembly, string hintPath)
143 if (string.IsNullOrEmpty (gacAssembly)) {
144 reference = string.Format (
145 @"<Reference Include='{0}'>
146 <HintPath>{1}</HintPath>
147 </Reference>", System.IO.Path.GetFileNameWithoutExtension (hintPath), hintPath);
149 reference = string.Format (
150 @"<Reference Include='{0}'/>", gacAssembly);
154 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
160 {CandidateAssemblyFiles};
163 {TargetFrameworkDirectory};
171 <ResolveAssemblyReference
172 Assemblies='@(Reference)'
173 SearchPaths='$(SearchPaths)'
175 <Output TaskParameter='ResolvedFiles' ItemName='ResolvedFiles'/>
176 <Output TaskParameter='ResolvedDependencyFiles' ItemName='ResolvedDependencyFiles'/>
177 </ResolveAssemblyReference>