void ResolveFiles(ReferenceFolder folder)
        {
            FileList found = new FileList();

            found.FileFound     += new EventHandler <FileList.FileFoundEventArgs>(FileFound);
            found.RecurseFolders = folder.Recursive;
            found.Add(folder.AbsolutePath(_namedValues));

            ReferenceWorkItem item;

            foreach (FileInfo file in found)
            {
                string filenameonly = Path.GetFileNameWithoutExtension(file.Name);
                if (!_assemblyNameToFile.TryGetValue(filenameonly, out item))
                {
                    _assemblyNameToFile.Add(filenameonly, item = new ReferenceWorkItem());
                }

                item.FullPath = file.FullName;
                item.FoundIn  = folder;
            }
        }
        protected override int Run(BuildEngine engine)
        {
            int errors = 0;

            engine.ProjectPreBuild += new ProjectPreBuildEventHandler(ProjectPreBuild);
            foreach (ReferenceFolder fld in _folders)
            {
                ResolveFiles(fld);
            }

            ReferenceWorkItem refItem;
            ProjectInfo       refProj;

            AssemblyName mscorlib = new AssemblyName("mscorlib");

            foreach (ProjectInfo project in engine.Projects)
            {
                SetOptions(project);
                bool msCoreFound = false;
                foreach (ReferenceInfo reference in project.References)
                {
                    msCoreFound |= StringComparer.OrdinalIgnoreCase.Equals(mscorlib.Name, reference.Assembly.Name);
                    refItem      = new ReferenceWorkItem();

                    if (engine.Projects.TryGetProject(reference, out refProj))
                    {
                        refItem.FullPath = refProj.TargetFullName;
                    }
                    else if (!String.IsNullOrEmpty(reference.Assembly.Name) && _assemblyNameToFile.TryGetValue(reference.Assembly.Name, out refItem))
                    {
                    }
                    else if (!_strict)
                    {
                        continue;
                    }             //ignore unknown reference
                    else
                    {
                        if (++errors > 0 && !_failedReferences.ContainsKey(reference.Assembly.Name))
                        {
                            Log.Error("Unable to locate reference in project {1}\r\n{2}", reference.Assembly, project.ProjectFile, reference.Details);
                            _failedReferences[reference.Assembly.Name] = reference.Assembly.Name;
                        }
                        continue; //failed to locate
                    }
                    if (_noprojectrefs && reference.RefType == ReferenceType.ProjectReference)
                    {
                        if (refProj == null)
                        {
                            Log.Error("Unable to locate project referenced by {1}\r\n{2}", reference.ProjectFile, project.ProjectFile, reference.Details);
                            errors++;
                        }
                        reference.MakeReference(new AssemblyName(refProj.AssemblyName), refItem.FullPath);
                    }
                    else
                    {
                        if ((_strict || !String.IsNullOrEmpty(reference.HintPath)) &&
                            !StringComparer.OrdinalIgnoreCase.Equals(reference.HintPath, refItem.FullPath))
                        {
                            reference.HintPath = refItem.FullPath;
                        }
                    }

                    if (reference.SpecificVersion == false && reference.Assembly.Version != null)
                    {
                        reference.Assembly = new AssemblyName(reference.Assembly.Name);
                    }
                }

                if (!msCoreFound && _noStdLib)
                {
                    if (!_strict)
                    {
                        project.References.Add(mscorlib);
                    }
                    else if (_assemblyNameToFile.TryGetValue(mscorlib.Name, out refItem))
                    {
                        project.References.Add(mscorlib, refItem.FullPath);
                    }
                    else
                    {
                        Log.Info("Unable to locate {0} in references.\r\n" +
                                 "When enabling no-standard-references and strict-references, you must specify\r\n" +
                                 "a reference path that contains the {0}.dll version to use.", mscorlib);
                        throw new ApplicationException(String.Format("Aborted due to missing {0} library.", mscorlib));
                    }
                }
            }
            return(errors);
        }
		protected override int Run(BuildEngine engine)
		{
			int errors = 0;
			engine.ProjectPreBuild += new ProjectPreBuildEventHandler(ProjectPreBuild);
			foreach (ReferenceFolder fld in _folders)
				ResolveFiles(fld);

			ReferenceWorkItem refItem;
			ProjectInfo refProj;

			AssemblyName mscorlib = new AssemblyName("mscorlib");

			foreach (ProjectInfo project in engine.Projects)
			{
				SetOptions(project);
				bool msCoreFound = false;
				foreach (ReferenceInfo reference in project.References)
				{
					msCoreFound |= StringComparer.OrdinalIgnoreCase.Equals(mscorlib.Name, reference.Assembly.Name);
					refItem = new ReferenceWorkItem();

                    if (engine.Projects.TryGetProject(reference, out refProj))
                        refItem.FullPath = refProj.TargetFullName;
                    else if (!String.IsNullOrEmpty(reference.Assembly.Name) && _assemblyNameToFile.TryGetValue(reference.Assembly.Name, out refItem))
                    { }
                    else if (!_strict)
                    { continue; } //ignore unknown reference
                    else
                    {
                        if (++errors > 0 && !_failedReferences.ContainsKey(reference.Assembly.Name))
                        {
                            Log.Error("Unable to locate reference in project {1}\r\n{2}", reference.Assembly, project.ProjectFile, reference.Details);
                            _failedReferences[reference.Assembly.Name] = reference.Assembly.Name;
                        }
                        continue; //failed to locate
                    }
					if (_noprojectrefs && reference.RefType == ReferenceType.ProjectReference)
					{
						if (refProj == null)
						{
							Log.Error("Unable to locate project referenced by {1}\r\n{2}", reference.ProjectFile, project.ProjectFile, reference.Details);
							errors++;
						}
						reference.MakeReference(new AssemblyName(refProj.AssemblyName), refItem.FullPath);
					}
					else
					{
						if ((_strict || !String.IsNullOrEmpty(reference.HintPath)) &&
							!StringComparer.OrdinalIgnoreCase.Equals(reference.HintPath, refItem.FullPath))
							reference.HintPath = refItem.FullPath;
					}

					if (reference.SpecificVersion == false && reference.Assembly.Version != null)
						reference.Assembly = new AssemblyName(reference.Assembly.Name);
				}

				if (!msCoreFound && _noStdLib)
				{
					if (!_strict)
						project.References.Add(mscorlib);
					else if (_assemblyNameToFile.TryGetValue(mscorlib.Name, out refItem))
						project.References.Add(mscorlib, refItem.FullPath);
					else
					{
						Log.Info("Unable to locate {0} in references.\r\n" +
						"When enabling no-standard-references and strict-references, you must specify\r\n" +
						"a reference path that contains the {0}.dll version to use.", mscorlib);
						throw new ApplicationException(String.Format("Aborted due to missing {0} library.", mscorlib));
					}
				}
			}
			return errors;
		}
		void ResolveFiles(ReferenceFolder folder)
		{
			FileList found = new FileList();
			found.FileFound += new EventHandler<FileList.FileFoundEventArgs>(FileFound);
			found.RecurseFolders = folder.Recursive;
            found.Add(folder.AbsolutePath(_namedValues));

			ReferenceWorkItem item;
			
			foreach (FileInfo file in found)
			{
				string filenameonly = Path.GetFileNameWithoutExtension(file.Name);
				if(!_assemblyNameToFile.TryGetValue(filenameonly, out item))
					_assemblyNameToFile.Add(filenameonly, item = new ReferenceWorkItem());
				
				item.FullPath = file.FullName;
				item.FoundIn = folder;
			}
		}