public void AddDependencies(ProjectInfo[] depends) { foreach (ProjectInfo proj in depends) { BuildItem bi = new BuildItem("Reference", proj.AssemblyName); bi.SetMetadata("SpecificVersion", false.ToString()); bi.SetMetadata("HintPath", proj.AbsoluteOutputPath); _psedoDepends.Add(new ProjectRef(bi, GetProjectPath)); } }
bool ProjectLoaded(ProjectInfo item) { string reason; if (!_instance.AllowProject(item, out reason)) { if (reason != null) Log.Warning("Ignoring project {0}, reason = {1}", item.AssemblyName, reason); return false; } return true; }
int RebindProjectReferences(ProjectInfo item) { if (GetReferenceFolders().Length == 0) return 0; string file = null; if (__mscorlibPath == null) __mscorlibPath = FindPath(__mscorlib); item.AddReference(null, __mscorlib, null, __mscorlibPath, false, false); int errors = 0; List<ProjectRef> refs = new List<ProjectRef>(item.GetReferences()); foreach (ProjectRef r in refs) { if (!_foundReferences.TryGetValue(r.Assembly.Name, out file)) { if (r.Resolved) { ProjectInfo proj = _build.GetReference(r); if (proj == null) throw new ApplicationException(String.Format("Unable to remove unkown project reference {0}", r.Assembly)); file = proj.AbsoluteOutputPath; } else { file = FindPath(r.Assembly); } _foundReferences[r.Assembly.Name] = file; } if (file != null) { item.ResolveReference(r, file, r.CopyLocal, r.SpecificVersion); Log.Verbose("Project reference {0} changed to file {1}", r.Assembly.Name, file); } else { Log.Error("Unable to locate reference {0}", r.Assembly); errors++; } } return errors; }
int ApplyBuildRules(ProjectInfo item) { if(_target.TargetFramework != null) item.TargetFrameworkVersion = _target.TargetFramework.Version.ToString().Insert(2, "."); if (_target.IntermediateFiles != null) item.IntermediateFiles = _target.IntermediateFiles.AbsolutePath; if (_target.OutputPath != null) item.OutputPath = _target.OutputPath.AbsolutePath; if (_target.DefineConstants != null && _target.DefineConstants.Length > 0) { StringBuilder sb = new StringBuilder(); sb.Append(item.GetProperty("DefineConstants")); foreach (BuildDefineConst set in _target.DefineConstants) { if (sb.Length > 0) sb.Append(','); sb.Append(set.Value); } item.SetProperty("DefineConstants", sb.ToString()); } return 0; }
int RestrictFrameworkReferences(ProjectInfo item) { string targetFrmWrk = item.TargetFrameworkVersion; if (!String.IsNullOrEmpty(targetFrmWrk)) { Version targetVer = new Version(targetFrmWrk.TrimStart('v')); foreach (ProjectRef r in item.GetReferences()) { if (!String.IsNullOrEmpty(r.RequiresVersion)) { if (new Version(r.RequiresVersion) > targetVer) { item.RemoveReference(r); continue; } } if (r.Assembly.Version != null &&r.Assembly.Name.StartsWith("System.", StringComparison.OrdinalIgnoreCase)) { Version ver = new Version(r.Assembly.Version.Major, r.Assembly.Version.Minor); if (r.Assembly.Version > targetVer) { item.RemoveReference(r); } } } } return 0; }
int SetSolutionDir(ProjectInfo item) { //To attempt to gracefully handle those those that use SolutionDir in build rules... string solutiondir = Path.GetDirectoryName(item.FullName); DirectoryInfo parent = new DirectoryInfo(solutiondir); while (parent != null) { if (parent.GetFiles("*.sln").Length > 0) { solutiondir = parent.FullName; break; } parent = parent.Parent; } if (!solutiondir.EndsWith(@"\")) solutiondir += @"\"; _build.SetProperty("SolutionDir", solutiondir); return 0; }
private int FixupProjectForBuild(ProjectInfo item) { int errors = 0; errors += SetSolutionDir(item); errors += ApplyBuildRules(item); errors += RestrictFrameworkReferences(item); errors += RebindProjectReferences(item); return errors; }
private bool AllowProject(ProjectInfo item, out string reason) { //We can't build ourselves... if (item.AssemblyName == MyAssemblyName) { reason = null; return false; } string curTargetFramework = item.TargetFrameworkVersion; if (curTargetFramework != null) { FrameworkVersions curTargetVer = (FrameworkVersions)Enum.Parse(typeof(FrameworkVersions), curTargetFramework.Replace(".", "")); //If they do not want to build for each framework version, then we do not build lower versions if (_target.Toolset < curTargetVer) { //reason = "Target framework is " + item.TargetFrameworkVersion.ToString(); //return false; } } reason = null; return true; }
public bool AddReference(string grpCondition, ProjectInfo project) { BuildItemGroup grpAdding = FristReferenceGroup(grpCondition); string file = this.MakeProjectRelativePath(project.FullName); BuildItem addedItem = grpAdding.AddNewItem("ProjectReference", file); addedItem.SetMetadata("Project", project.ProjectGuid.ToString().ToUpper()); addedItem.SetMetadata("Name", project.AssemblyName); _refCache.Add(new ProjectRef(addedItem, GetProjectPath)); return true; }
public void CopyTo(ProjectInfo[] array, int arrayIndex) { _items.CopyTo(array, arrayIndex); }
public ProjectPropetyChangedEventArgs(ProjectInfo project, string property, string newValue) { this.Project = project; this.Property = property; }
public bool Contains(ProjectInfo item) { return _items.Contains(item); }
public bool Remove(ProjectInfo item) { if (!_items.Contains(item)) return false; _items.Remove(item); item.Unload(); return true; }
public void Add(ProjectInfo item) { _items.Add(item); }
public int RunTarget(ProjectInfo[] sorted, string[] targets) { int errors = 0; if (targets == null || targets.Length == 0) targets = new string[] {null}; using (Log.Start("Building targets {0} on {1} projects", String.Join(",",targets), sorted.Length)) { foreach (ProjectInfo proj in sorted) { if (targets == null || targets.Length == 0 || (targets.Length == 1 && String.IsNullOrEmpty(targets[0]))) targets = proj.DefaultTargets; using (Log.Start("{0} {1}", String.Join(",", targets), proj.AssemblyName)) { Log.Info(Path.GetFileName(proj.FullName)); //proj.SaveTo(Path.ChangeExtension(proj.ProjectFile, ".tmp")); Project msProject = ((IMSProjectItem)proj).GetMSProject(); if (!_engine.BuildProject(msProject, targets, null, BuildSettings.DoNotResetPreviouslyBuiltTargets)) { Log.Error("Assembly {0} Failed to build.", proj.AssemblyName); errors++; } } } } return errors; }
public bool LoadProject(string projFile, out ProjectInfo item) { object[] ctorargs = new object[] { _engine }; if( Is35 ) ctorargs = new object[] { _engine, _toolsVersion }; Project prj = (Project)typeof(Project).InvokeMember(null, BindingFlags.CreateInstance, null, null, ctorargs); try { prj.Load(projFile); } catch (Exception e) { Log.Error("Invalid Project: {0}\r\n\t{1}", projFile, e.Message); item = null; return false; } item = new ProjectInfo(prj); if (ProjectLoaded != null) { if (!ProjectLoaded(item)) return false; } this.Add(item); return true; }