/// <summary> /// Gets the token replacement file extension. /// </summary> /// <param name="project">The project.</param> /// <returns></returns> public static List <string> GetTokenReplacementFileExtension(EnvDTE.Project project) { Eval.Project prj = Eval.ProjectCollection.GlobalProjectCollection.GetLoadedProjects(project.FullName).FirstOrDefault(); if (prj == null) { prj = new Eval.Project(project.FullName); } Eval.ProjectProperty prop = prj.GetProperty("TokenReplacementFileExtensions"); if (prop != null) { List <string> elements = new List <string>(prop.EvaluatedValue.Split(';')); List <string> distinctElements = elements.Distinct().ToList(); distinctElements.RemoveAll(p => p == String.Empty); return(distinctElements); } else { return(null); } }
private string GetValue(bool finalValue, IList <ProjectConfig> configs, bool booleanValue) { MSBuild.Project buildProject = this.PerUser ? this.project.UserBuildProject : this.project.BuildProject; if (buildProject == null) { return(null); } string value; if (this.PerConfig) { if (configs == null || configs.Count == 0) { configs = new ProjectConfig[] { this.project.CurrentConfig }; } value = this.GetPerConfigValue(buildProject, finalValue, configs, booleanValue); } else { MSBuild.ProjectProperty buildProperty = buildProject.GetProperty(this.propertyName); value = this.GetBuildPropertyValue(buildProperty, finalValue); if (booleanValue && String.IsNullOrEmpty(value)) { value = Boolean.FalseString; } } return(value); }
private string GetBuildPropertyValue(MSBuild.ProjectProperty buildProperty, bool finalValue) { if (buildProperty == null) { return(null); } else if (finalValue) { return(buildProperty.EvaluatedValue); } else { // If the property definition contains the property itself, we want to return the final result // Ideally, we would like to expand only the value for the property but MSBuild does not allow that // That solves the case where OutputPath is define as $(OutputPath)\ if it's not ending with a backslash string propertyNameEscaped = "$(" + this.propertyName + ")"; if (buildProperty.EvaluatedValue.Contains(propertyNameEscaped)) { return(buildProperty.UnevaluatedValue); } else { return(this.Unescape(buildProperty.UnevaluatedValue)); } } }
private static void PrintPropertyInfo(MBEV.ProjectProperty property, int indentCount) { var indent = new string('\t', indentCount); string location; if (property.IsEnvironmentProperty) { location = "(environment)"; } else if (property.IsReservedProperty) { location = "(reserved)"; } else { location = $"{property.Xml.Location.File}:{property.Xml.Location.Line}"; } Utils.WriteColor($"{indent}Loc: ", ConsoleColor.White); Utils.WriteLineColor(location, ConsoleColor.DarkCyan); if (property.UnevaluatedValue == property.EvaluatedValue) { Utils.WriteColor($"{indent}Val: ", ConsoleColor.White); Utils.WriteLineColor(property.EvaluatedValue, ConsoleColor.Green); } else { Utils.WriteColor($"{indent}Val: ", ConsoleColor.White); Utils.WriteLineColor(property.UnevaluatedValue, ConsoleColor.DarkGreen); Utils.WriteColor($"{indent} ", ConsoleColor.White); Utils.WriteLineColor(property.EvaluatedValue, ConsoleColor.Green); } }
private DirectoryInfo GetFolderPath(string projectFileFullPath, string propertyName) { Microsoft.Build.Evaluation.Project msbuildProject = ProjectLoader.LoadProject(projectFileFullPath); ProjectProperty property = msbuildProject.GetProperty(propertyName); string expandString = msbuildProject.ExpandString(property.UnevaluatedValue); return(new DirectoryInfo(expandString)); }
public static void Trace(MBEV.ProjectProperty property, int traceLevel = 0) { if (property == null || property.IsGlobalProperty || property.IsReservedProperty) { return; } PrintPropertyInfo(property, traceLevel); if (property.IsImported) { Trace(property.Predecessor, traceLevel + 1); } }
public MSBuildProperties(ProjectProperty property) { this.Name = property.Name; this.InitialValue = property.UnevaluatedValue; this.EvaluatedValue = property.EvaluatedValue; this.IsEnvironmentProperty = property.IsEnvironmentProperty; this.IsGlobalProperty = property.IsGlobalProperty; this.IsImported = property.IsImported; this.IsReservedProperty = property.IsReservedProperty; if (property.Xml != null) { this.Condition = property.Xml.Condition; this.ContainingProject = property.Xml.ContainingProject.FullPath; } }
/// <summary> /// Adds a file extension to the TokenReplacementFileExtensions project property /// </summary> /// <param name="project">The project file to be altered</param> /// <param name="extension">The file extension to be added excluding and leading period (ie. svc) </param> public static void AddTokenReplacementFileExtension(EnvDTE.Project project, string extension) { Eval.Project prj = Eval.ProjectCollection.GlobalProjectCollection.GetLoadedProjects(project.FullName).FirstOrDefault(); if (prj == null) { prj = new Eval.Project(project.FullName); } Eval.ProjectProperty prop = prj.GetProperty("TokenReplacementFileExtensions"); string val; if (prop != null) { List <string> elements = new List <string>(prop.EvaluatedValue.Split(';')); List <string> distinctElements = elements.Distinct().ToList(); distinctElements.RemoveAll(p => p == String.Empty); if (!distinctElements.Contains(extension)) { distinctElements.Add(extension); } StringBuilder sb = new StringBuilder("$(TokenReplacementFileExtensions);"); foreach (string item in distinctElements) { sb.Append(item + ";"); } val = sb.ToString(); } else { val = "$(TokenReplacementFileExtensions);" + extension + ";"; } prop = prj.SetProperty("TokenReplacementFileExtensions", val); }
private string GetPerConfigValue(MSBuild.Project buildProject, bool finalValue, IList <ProjectConfig> configs, bool nullIsFalse) { string unifiedValue = null; for (int i = 0; i < configs.Count; i++) { ProjectConfig config = configs[i]; bool resetCache = (i == 0); // we should be using the buildProject parameter here, but this isn't implemented in MPF MSBuild.ProjectProperty buildProperty = config.GetMsBuildProperty(this.propertyName, resetCache); string value = this.GetBuildPropertyValue(buildProperty, finalValue); if (value != null) { value = value.Trim(); } if (nullIsFalse && String.IsNullOrEmpty(value)) { value = Boolean.FalseString; } if (i == 0) { unifiedValue = value; } else if (unifiedValue != value) { unifiedValue = null; // indicates indeterminate value break; } } return(unifiedValue); }
public static string GetPropertyValueEscaped(ProjectProperty property) { // WTF happens here. //return ProjectCollection.Escape (property.EvaluatedValue); return(property.EvaluatedValue); }
public bool RemoveProperty (ProjectProperty property) { throw new NotImplementedException (); }
public static ProjectProperty ShouldUnevaluatedEquivalentTo <T>(this ProjectProperty property, T value, Func <EquivalencyAssertionOptions <T>, EquivalencyAssertionOptions <T> > config, string because = "", params object[] becauseArgs) { InternalShouldEquivalentTo(property.UnevaluatedValue, value, property.Project, config, because, becauseArgs); return(property); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="owner">The owning property page</param> /// <param name="buildProperty">The build property to edit or null for a new property</param> public PropertyItem(UserDefinedPropertiesPageControl owner, ProjectProperty buildProperty) { string newPropName; int idx = 1; this.Owner = owner; projProp = buildProperty; if(projProp != null) { name = projProp.Name; condition = projProp.Xml.Condition; propValue = projProp.UnevaluatedValue; } else { do { newPropName = "NewProperty" + idx.ToString(CultureInfo.InvariantCulture); idx++; } while(!this.Owner.Project.IsValidUserDefinedPropertyName(newPropName) || this.Owner.UserDefinedProperties.Where(p => p.Name == newPropName).Count() != 0); name = newPropName; propValue = String.Empty; } }
public bool RemoveProperty(ProjectProperty property) { throw new NotImplementedException(); }
public static string GetPropertyValueEscaped(ProjectProperty property) { throw new NotImplementedException(); }
/// <summary> /// Determines whether this property is a predecessor to another definition in the project. /// </summary> /// <param name="property"></param> /// <param name="project">The project to look in</param> /// <returns></returns> public static bool IsPredecessor(this MBEV.ProjectProperty property, MBEV.Project project) { return(project.AllEvaluatedProperties.Any(p => p.Predecessor == property)); }
/// <summary> /// Creates a regular evaluated property, with backing XML. /// Called by Project.SetProperty. /// Property MAY NOT have reserved name and MAY NOT overwrite a global property. /// Predecessor is any immediately previous property that was overridden by this one during evaluation and may be null. /// </summary> internal ProjectPropertyXmlBackedWithPredecessor(Project project, ProjectPropertyElement xml, string evaluatedValueEscaped, ProjectProperty predecessor) : base(project, xml, evaluatedValueEscaped) { ErrorUtilities.VerifyThrowArgumentNull(predecessor, "predecessor"); _predecessor = predecessor; }
public static string GetPropertyValueEscaped (ProjectProperty property) { throw new NotImplementedException (); }
private static bool IsGlobalProperty(ProjectProperty projectProperty) { // This property isn't available on xbuild (mono) var property = typeof(ProjectProperty).GetProperty("IsGlobalProperty", BindingFlags.Public | BindingFlags.Instance); if(property != null) { return (bool)property.GetValue(projectProperty, null); } // REVIEW: Maybe there's something better we can do on mono // Just return false if the property isn't there return false; }
public static ProjectProperty ShouldUnevaluatedEquivalentTo <T>(this ProjectProperty property, T value, string because = "", params object[] becauseArgs) { InternalShouldEquivalentTo(property.UnevaluatedValue, value, property.Project, t => t, because, becauseArgs); return(property); }