本文整理汇总了C#中MonoDevelop.Projects.MSBuild.MSBuildEvaluationContext类的典型用法代码示例。如果您正苦于以下问题:C# MSBuildEvaluationContext类的具体用法?C# MSBuildEvaluationContext怎么用?C# MSBuildEvaluationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MSBuildEvaluationContext类属于MonoDevelop.Projects.MSBuild命名空间,在下文中一共展示了MSBuildEvaluationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MSBuildEvaluationContext
public MSBuildEvaluationContext (MSBuildEvaluationContext parentContext)
{
this.parentContext = parentContext;
this.project = parentContext.project;
this.propertiesWithTransforms = parentContext.propertiesWithTransforms;
this.propertiesWithTransformsSorted = parentContext.propertiesWithTransformsSorted;
}
示例2: Evaluate
void Evaluate (ProjectInfo project, MSBuildEvaluationContext context, MSBuildTarget target)
{
// TODO NPM
project.Targets.Add (target);
}
示例3: SafeParseAndEvaluate
static bool SafeParseAndEvaluate (ProjectInfo project, MSBuildEvaluationContext context, string condition, bool collectConditionedProperties = false)
{
try {
if (String.IsNullOrEmpty (condition))
return true;
try {
ConditionExpression ce = ConditionParser.ParseCondition (condition);
if (!ce.CanEvaluateToBool (context))
throw new InvalidProjectFileException (String.Format ("Can not evaluate \"{0}\" to bool.", condition));
if (collectConditionedProperties)
ce.CollectConditionProperties (project.ConditionedProperties);
return ce.BoolEvaluate (context);
} catch (ExpressionParseException epe) {
throw new InvalidProjectFileException (
String.Format ("Unable to parse condition \"{0}\" : {1}", condition, epe.Message),
epe);
} catch (ExpressionEvaluationException epe) {
throw new InvalidProjectFileException (
String.Format ("Unable to evaluate condition \"{0}\" : {1}", condition, epe.Message),
epe);
}
}
catch {
// The condition is likely to be invalid
return false;
}
}
示例4: Evaluate
void Evaluate (ProjectInfo project, MSBuildEvaluationContext context, MSBuildChoose choose, bool evalItems)
{
foreach (var op in choose.GetOptions ()) {
if (op.IsOtherwise || SafeParseAndEvaluate (project, context, op.Condition, true)) {
EvaluateObjects (project, context, op.GetAllObjects (), evalItems);
break;
}
}
}
示例5: GetImportFiles
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;
}
}
示例6: CreateEvaluatedItem
static MSBuildItemEvaluated CreateEvaluatedItem (MSBuildEvaluationContext context, ProjectInfo pinfo, MSBuildProject project, MSBuildItem sourceItem, string include)
{
var it = new MSBuildItemEvaluated (project, sourceItem.Name, sourceItem.Include, include);
var md = new Dictionary<string,IMSBuildPropertyEvaluated> ();
foreach (var c in sourceItem.Metadata.GetProperties ()) {
if (string.IsNullOrEmpty (c.Condition) || SafeParseAndEvaluate (pinfo, context, c.Condition, true))
md [c.Name] = new MSBuildPropertyEvaluated (project, c.Name, c.Value, context.EvaluateString (c.Value));
}
((MSBuildPropertyGroupEvaluated)it.Metadata).SetProperties (md);
it.SourceItem = sourceItem;
it.Condition = sourceItem.Condition;
return it;
}
示例7: ExecuteTransformIncludeItemFunction
static bool ExecuteTransformIncludeItemFunction (MSBuildEvaluationContext context, MSBuildItemEvaluated item, string itemFunction, object [] itemFunctionArgs, out string evaluatedInclude, out bool skip)
{
evaluatedInclude = null;
skip = false;
switch (itemFunction) {
case "DirectoryName":
var path = MSBuildProjectService.FromMSBuildPath (context.Project.BaseDirectory, item.Include);
evaluatedInclude = Path.GetDirectoryName (path);
return true;
case "Metadata":
if (itemFunctionArgs.Length != 1)
return false;
var p = item.Metadata.GetProperty (itemFunctionArgs [0].ToString ());
if (p == null) {
skip = true;
return true;
} else {
evaluatedInclude = p.Value;
return true;
}
}
if (knownStringItemFunctions.Contains (itemFunction)) {
object res;
if (context.EvaluateMember (itemFunction, typeof (string), itemFunction, item.Include, itemFunctionArgs, out res)) {
evaluatedInclude = res.ToString ();
return true;
}
}
return false;
}
示例8: ParseTransformExpression
static bool ParseTransformExpression (MSBuildEvaluationContext context, string include, out string itemName, out string expression, out string itemFunction, out object [] itemFunctionArgs)
{
// This method parses the transforms and extracts: the name of the item list to transform, the whole transform expression (or null if there isn't). If the expression can be
// parsed as an item funciton, then it returns the function name and the list of arguments. Otherwise those parameters are null.
expression = null;
itemFunction = null;
itemFunctionArgs = null;
int i = include.IndexOf ("->", StringComparison.Ordinal);
if (i == -1) {
itemName = include.Trim ();
return itemName.Length > 0;
}
itemName = include.Substring (0, i).Trim ();
if (itemName.Length == 0)
return false;
expression = include.Substring (i + 2).Trim ();
if (expression.Length > 1 && expression[0]=='\'' && expression[expression.Length - 1] == '\'') {
expression = expression.Substring (1, expression.Length - 2);
return true;
}
i = expression.IndexOf ('(');
if (i == -1)
return true;
var func = expression.Substring (0, i).Trim ();
if (knownItemFunctions.Contains (func)) {
itemFunction = func;
i++;
context.EvaluateParameters (expression, ref i, out itemFunctionArgs);
return true;
}
return true;
}
示例9: ExecuteStringTransform
internal static bool ExecuteStringTransform (List<MSBuildItemEvaluated> evaluatedItemsCollection, MSBuildEvaluationContext context, string transformExp, out string items)
{
// This method works mostly like ExecuteTransform, but instead of returning a list of items, it returns a string as result.
// Since there is no need to create full blown evaluated items, it can be more efficient than ExecuteTransform.
items = "";
string itemName, expression, itemFunction; object [] itemFunctionArgs;
if (!ParseTransformExpression (context, transformExp, out itemName, out expression, out itemFunction, out itemFunctionArgs))
return false;
var transformItems = evaluatedItemsCollection.Where (i => i.Name == itemName).ToArray ();
if (itemFunction != null) {
string result; bool ignoreMetadata;
if (ExecuteSummaryItemFunction (transformItems, itemFunction, itemFunctionArgs, out result)) {
// The item function returns a value. Just return it.
items = result;
return true;
} else if (ExecuteTransformItemListFunction (ref transformItems, itemFunction, itemFunctionArgs, out ignoreMetadata)) {
var sb = new StringBuilder ();
for (int n = 0; n < transformItems.Length; n++) {
if (n > 0)
sb.Append (';');
sb.Append (transformItems[n].Include);
}
items = sb.ToString ();
return true;
}
}
var sbi = new StringBuilder ();
int count = 0;
foreach (var eit in transformItems) {
context.SetItemContext (eit.Include, null, eit.Metadata);
try {
string evaluatedInclude; bool skip;
if (itemFunction != null && ExecuteTransformIncludeItemFunction (context, eit, itemFunction, itemFunctionArgs, out evaluatedInclude, out skip)) {
if (skip) continue;
} else if (expression != null)
evaluatedInclude = context.EvaluateString (expression);
else
evaluatedInclude = eit.Include;
if (count++ > 0)
sbi.Append (';');
sbi.Append (evaluatedInclude);
} finally {
context.ClearItemContext ();
}
}
items = sbi.ToString ();
return true;
}
示例10: ExecuteTransform
static bool ExecuteTransform (ProjectInfo project, MSBuildEvaluationContext context, MSBuildItem item, string transformExp, out List<MSBuildItemEvaluated> items)
{
bool ignoreMetadata = false;
items = new List<MSBuildItemEvaluated> ();
string itemName, expression, itemFunction; object [] itemFunctionArgs;
// This call parses the transforms and extracts: the name of the item list to transform, the whole transform expression (or null if there isn't). If the expression can be
// parsed as an item funciton, then it returns the function name and the list of arguments. Otherwise those parameters are null.
if (!ParseTransformExpression (context, transformExp, out itemName, out expression, out itemFunction, out itemFunctionArgs))
return false;
// Get the items mathing the referenced item list
var transformItems = project.EvaluatedItems.Where (i => i.Name == itemName).ToArray ();
if (itemFunction != null) {
// First of all, try to execute the function as a summary function, that is, a function that returns a single value for
// the whole list (such as Count).
// After that, try executing as a list transformation function: a function that changes the order or filters out items from the list.
string result;
if (ExecuteSummaryItemFunction (transformItems, itemFunction, itemFunctionArgs, out result)) {
// The item function returns a value. Just create an item with that value
var newItem = new MSBuildItemEvaluated (project.Project, item.Name, item.Include, result);
project.EvaluatedItemsIgnoringCondition.Add (newItem);
items.Add (newItem);
return true;
} else if (ExecuteTransformItemListFunction (ref transformItems, itemFunction, itemFunctionArgs, out ignoreMetadata)) {
expression = null;
itemFunction = null;
}
}
foreach (var eit in transformItems) {
// Some item functions cause the erasure of metadata. Take that into account now.
context.SetItemContext (eit.Include, null, ignoreMetadata || item == null ? null : eit.Metadata);
try {
// If there is a function that transforms the include of the item, it needs to be applied now. Otherwise just use the transform expression
// as include, or the transformed item include if there is no expression.
string evaluatedInclude; bool skip;
if (itemFunction != null && ExecuteTransformIncludeItemFunction (context, eit, itemFunction, itemFunctionArgs, out evaluatedInclude, out skip)) {
if (skip) continue;
} else if (expression != null)
evaluatedInclude = context.EvaluateString (expression);
else
evaluatedInclude = eit.Include;
var newItem = new MSBuildItemEvaluated (project.Project, item.Name, item.Include, evaluatedInclude);
if (!ignoreMetadata) {
var md = new Dictionary<string, IMSBuildPropertyEvaluated> ();
// Add metadata from the evaluated item
var col = (MSBuildPropertyGroupEvaluated)eit.Metadata;
foreach (var p in col.GetRegisteredProperties ()) {
md [p.Name] = new MSBuildPropertyEvaluated (project.Project, p.Name, p.UnevaluatedValue, p.Value);
}
// Now override metadata from the new item definition
foreach (var c in item.Metadata.GetProperties ()) {
if (string.IsNullOrEmpty (c.Condition) || SafeParseAndEvaluate (project, context, c.Condition, true))
md [c.Name] = new MSBuildPropertyEvaluated (project.Project, c.Name, c.Value, context.EvaluateString (c.Value));
}
((MSBuildPropertyGroupEvaluated)newItem.Metadata).SetProperties (md);
}
newItem.SourceItem = item;
newItem.Condition = item.Condition;
items.Add (newItem);
} finally {
context.ClearItemContext ();
}
}
return true;
}
示例11: AddItem
static void AddItem (ProjectInfo project, MSBuildEvaluationContext context, MSBuildItem item, MSBuildItemEvaluated it, string include, Regex excludeRegex, bool trueCond)
{
// Don't add the result from any item that has an empty include. MSBuild never returns those.
if (include == string.Empty)
return;
if (IsIncludeTransform (include)) {
// This is a transform
List<MSBuildItemEvaluated> evalItems;
var transformExp = include.Substring (2, include.Length - 3);
if (ExecuteTransform (project, context, item, transformExp, out evalItems)) {
foreach (var newItem in evalItems) {
project.EvaluatedItemsIgnoringCondition.Add (newItem);
if (trueCond)
project.EvaluatedItems.Add (newItem);
}
}
} else if (include.IndexOf ('*') != -1) {
var path = include;
if (path == "**" || path.EndsWith ("\\**"))
path = path + "/*";
var subpath = path.Split ('\\');
foreach (var eit in ExpandWildcardFilePath (project, project.Project, context, item, project.Project.BaseDirectory, FilePath.Null, false, subpath, 0)) {
if (excludeRegex != null && excludeRegex.IsMatch (eit.Include))
continue;
project.EvaluatedItemsIgnoringCondition.Add (eit);
if (trueCond)
project.EvaluatedItems.Add (eit);
}
} else if (include != it.Include) {
if (excludeRegex != null && excludeRegex.IsMatch (include))
return;
it = CreateEvaluatedItem (context, project, project.Project, item, include);
project.EvaluatedItemsIgnoringCondition.Add (it);
if (trueCond)
project.EvaluatedItems.Add (it);
} else {
if (excludeRegex != null && excludeRegex.IsMatch (include))
return;
project.EvaluatedItemsIgnoringCondition.Add (it);
if (trueCond)
project.EvaluatedItems.Add (it);
}
}
示例12: EvaluateProject
void EvaluateProject (ProjectInfo pi, MSBuildEvaluationContext context, bool evalItems)
{
context.InitEvaluation (pi.Project);
EvaluateObjects (pi, context, pi.Project.GetAllObjects (), evalItems);
}
示例13: AddItem
static void AddItem (ProjectInfo project, MSBuildEvaluationContext context, MSBuildItem item, MSBuildItemEvaluated it, string include, Regex excludeRegex, bool trueCond)
{
if (include.IndexOf ('*') != -1) {
var path = include;
if (path == "**" || path.EndsWith ("\\**"))
path = path + "/*";
var subpath = path.Split ('\\');
foreach (var eit in ExpandWildcardFilePath (project, project.Project, context, item, project.Project.BaseDirectory, FilePath.Null, false, subpath, 0)) {
if (excludeRegex != null && excludeRegex.IsMatch (eit.Include))
continue;
project.EvaluatedItemsIgnoringCondition.Add (eit);
if (trueCond)
project.EvaluatedItems.Add (eit);
}
}
else if (include != it.Include) {
if (excludeRegex != null && excludeRegex.IsMatch (include))
return;
it = CreateEvaluatedItem (context, project, project.Project, item, include);
project.EvaluatedItemsIgnoringCondition.Add (it);
if (trueCond)
project.EvaluatedItems.Add (it);
}
else {
if (excludeRegex != null && excludeRegex.IsMatch (include))
return;
project.EvaluatedItemsIgnoringCondition.Add (it);
if (trueCond)
project.EvaluatedItems.Add (it);
}
}
示例14: Evaluate
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);
}
}
示例15: ExpandWildcardFilePath
static IEnumerable<MSBuildItemEvaluated> ExpandWildcardFilePath (ProjectInfo pinfo, MSBuildProject project, MSBuildEvaluationContext context, MSBuildItem sourceItem, FilePath basePath, FilePath baseRecursiveDir, bool recursive, string[] filePath, int index)
{
var res = Enumerable.Empty<MSBuildItemEvaluated> ();
if (index >= filePath.Length)
return res;
var path = filePath [index];
if (path == "..")
return ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath.ParentDirectory, baseRecursiveDir, recursive, filePath, index + 1);
if (path == ".")
return ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath, baseRecursiveDir, recursive, filePath, index + 1);
if (!Directory.Exists (basePath))
return res;
if (path == "**") {
// if this is the last component of the path, there isn't any file specifier, so there is no possible match
if (index + 1 >= filePath.Length)
return res;
// If baseRecursiveDir has already been set, don't overwrite it.
if (baseRecursiveDir.IsNullOrEmpty)
baseRecursiveDir = basePath;
return ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath, baseRecursiveDir, true, filePath, index + 1);
}
if (recursive) {
// Recursive search. Try to match the remaining subpath in all subdirectories.
foreach (var dir in Directory.GetDirectories (basePath))
res = res.Concat (ExpandWildcardFilePath (pinfo, project, context, sourceItem, dir, baseRecursiveDir, true, filePath, index));
}
if (index == filePath.Length - 1) {
// Last path component. It has to be a file specifier.
string baseDir = basePath.ToRelative (project.BaseDirectory).ToString().Replace ('/','\\');
if (baseDir == ".")
baseDir = "";
else if (!baseDir.EndsWith ("\\", StringComparison.Ordinal))
baseDir += '\\';
var recursiveDir = baseRecursiveDir.IsNullOrEmpty ? FilePath.Null : basePath.ToRelative (baseRecursiveDir);
res = res.Concat (Directory.GetFiles (basePath, path).Select (f => {
context.SetItemContext (f, recursiveDir);
var ev = baseDir + Path.GetFileName (f);
return CreateEvaluatedItem (context, pinfo, project, sourceItem, ev);
}));
}
else {
// Directory specifier
// Look for matching directories.
// The search here is non-recursive, not matter what the 'recursive' parameter says, since we are trying to match a subpath.
// The recursive search is done below.
if (path.IndexOfAny (wildcards) != -1) {
foreach (var dir in Directory.GetDirectories (basePath, path))
res = res.Concat (ExpandWildcardFilePath (pinfo, project, context, sourceItem, dir, baseRecursiveDir, false, filePath, index + 1));
} else
res = res.Concat (ExpandWildcardFilePath (pinfo, project, context, sourceItem, basePath.Combine (path), baseRecursiveDir, false, filePath, index + 1));
}
return res;
}