string[] GetImportFiles(ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, string extensionsPath) { var tempCtx = new MSBuildEvaluationContext(context); var mep = MSBuildProjectService.ToMSBuildPath(null, extensionsPath); tempCtx.SetPropertyValue("MSBuildExtensionsPath", mep); tempCtx.SetPropertyValue("MSBuildExtensionsPath32", mep); tempCtx.SetPropertyValue("MSBuildExtensionsPath64", mep); var pr = context.EvaluateString(import.Project); project.Imports [import] = pr; if (!string.IsNullOrEmpty(import.Condition) && !SafeParseAndEvaluate(project, tempCtx, import.Condition, true)) { return(null); } var path = MSBuildProjectService.FromMSBuildPath(project.Project.BaseDirectory, pr); var fileName = Path.GetFileName(path); if (fileName.IndexOfAny(new [] { '*', '?' }) == -1) { return(File.Exists(path) ? new [] { path } : null); } else { var files = Directory.GetFiles(Path.GetDirectoryName(path), fileName); Array.Sort(files); return(files); } }
public override void Evaluate(object projectInstance) { var pi = (ProjectInfo)projectInstance; pi.EvaluatedItemsIgnoringCondition.Clear(); pi.EvaluatedItems.Clear(); pi.Properties.Clear(); pi.Imports.Clear(); pi.Targets.Clear(); // Unload referenced projects after evaluating to avoid unnecessary unload + load var oldRefProjects = pi.ReferencedProjects; pi.ReferencedProjects = new List <MSBuildProject> (); try { var context = new MSBuildEvaluationContext(); foreach (var p in pi.GlobalProperties) { context.SetPropertyValue(p.Key, p.Value); pi.Properties [p.Key] = new PropertyInfo { Name = p.Key, Value = p.Value, FinalValue = p.Value }; } EvaluateProject(pi, context); } finally { foreach (var p in oldRefProjects) { UnloadProject(p); } DisposeImportedProjects(pi); pi.ImportedProjects.Clear(); } }
void Evaluate(ProjectInfo project, MSBuildEvaluationContext context, MSBuildProperty prop) { if (string.IsNullOrEmpty(prop.Condition) || SafeParseAndEvaluate(project, context, prop.Condition, true)) { var val = context.EvaluateString(prop.Value); project.Properties [prop.Name] = new PropertyInfo { Name = prop.Name, Value = prop.Value, FinalValue = val }; context.SetPropertyValue(prop.Name, val); } }
public void SetPropertyValue(string name, string value) { if (parentContext != null) { parentContext.SetPropertyValue(name, value); } else { properties [name] = value; } }
string[] GetImportFiles (ProjectInfo project, MSBuildEvaluationContext context, MSBuildImport import, string extensionsPath) { if (extensionsPath != null) { var tempCtx = new MSBuildEvaluationContext (context); var mep = MSBuildProjectService.ToMSBuildPath (null, extensionsPath); tempCtx.SetPropertyValue ("MSBuildExtensionsPath", mep); tempCtx.SetPropertyValue ("MSBuildExtensionsPath32", mep); tempCtx.SetPropertyValue ("MSBuildExtensionsPath64", mep); context = tempCtx; } var pr = context.EvaluateString (import.Project); project.Imports [import] = pr; if (!string.IsNullOrEmpty (import.Condition) && !SafeParseAndEvaluate (project, context, import.Condition, true)) return null; var path = MSBuildProjectService.FromMSBuildPath (project.Project.BaseDirectory, pr); var fileName = Path.GetFileName (path); if (fileName.IndexOfAny (new [] { '*', '?' }) == -1) { return File.Exists (path) ? new [] { path } : null; } else { var files = Directory.GetFiles (Path.GetDirectoryName (path), fileName); Array.Sort (files); return files; } }
void Evaluate (ProjectInfo project, MSBuildEvaluationContext context, MSBuildProperty prop) { if (string.IsNullOrEmpty (prop.Condition) || SafeParseAndEvaluate (project, context, prop.Condition, true)) { var val = context.EvaluateString (prop.Value); project.Properties [prop.Name] = new PropertyInfo { Name = prop.Name, Value = prop.Value, FinalValue = val }; context.SetPropertyValue (prop.Name, val); } }
public override void Evaluate (object projectInstance) { var pi = (ProjectInfo) projectInstance; pi.EvaluatedItemsIgnoringCondition.Clear (); pi.EvaluatedItems.Clear (); pi.Properties.Clear (); pi.Imports.Clear (); pi.Targets.Clear (); pi.TargetsIgnoringCondition.Clear (); // Unload referenced projects after evaluating to avoid unnecessary unload + load var oldRefProjects = pi.ReferencedProjects; pi.ReferencedProjects = new List<MSBuildProject> (); try { var context = new MSBuildEvaluationContext (); foreach (var p in pi.GlobalProperties) { context.SetPropertyValue (p.Key, p.Value); pi.Properties [p.Key] = new PropertyInfo { Name = p.Key, Value = p.Value, FinalValue = p.Value }; } EvaluateProject (pi, context); } finally { foreach (var p in oldRefProjects) UnloadProject (p); DisposeImportedProjects (pi); pi.ImportedProjects.Clear (); } }
void Evaluate (ProjectInfo project, MSBuildEvaluationContext context, MSBuildProperty prop) { if (string.IsNullOrEmpty (prop.Condition) || SafeParseAndEvaluate (project, context, prop.Condition, true)) { bool needsItemEvaluation; var val = context.Evaluate (prop.UnevaluatedValue, out needsItemEvaluation); if (needsItemEvaluation) context.SetPropertyNeedsTransformEvaluation (prop.Name); project.Properties [prop.Name] = new PropertyInfo { Name = prop.Name, Value = prop.UnevaluatedValue, FinalValue = val }; context.SetPropertyValue (prop.Name, val); } }
void EvaluateProject (ProjectInfo pi, MSBuildEvaluationContext context) { context.InitEvaluation (pi.Project); var objects = pi.Project.GetAllObjects (); // If there is a .user project file load it using a fake import item added at the end of the objects list if (File.Exists (pi.Project.FileName + ".user")) objects = objects.Concat (new MSBuildImport {Project = pi.Project.FileName + ".user" }); EvaluateObjects (pi, context, objects, false); EvaluateObjects (pi, context, objects, true); // Once items have been evaluated, we need to re-evaluate properties that contain item transformations // (or that contain references to properties that have transformations). foreach (var propName in context.GetPropertiesNeedingTransformEvaluation ()) { PropertyInfo prop; if (pi.Properties.TryGetValue (propName, out prop)) { // Execute the transformation prop.FinalValue = context.EvaluateWithItems (prop.FinalValue, pi.EvaluatedItems); // Set the resulting value back to the context, so other properties depending on this // one will get the new value when re-evaluated. context.SetPropertyValue (propName, prop.FinalValue); } } }