本文整理汇总了C#中MonoDevelop.Projects.MSBuild.MSBuildEvaluationContext.EvaluateString方法的典型用法代码示例。如果您正苦于以下问题:C# MSBuildEvaluationContext.EvaluateString方法的具体用法?C# MSBuildEvaluationContext.EvaluateString怎么用?C# MSBuildEvaluationContext.EvaluateString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MonoDevelop.Projects.MSBuild.MSBuildEvaluationContext
的用法示例。
在下文中一共展示了MSBuildEvaluationContext.EvaluateString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: Evaluate
void Evaluate (ProjectInfo project, MSBuildEvaluationContext context, MSBuildTarget target)
{
bool condIsTrue = SafeParseAndEvaluate (project, context, target.Condition);
var newTarget = new MSBuildTarget (target.Name, target.Tasks);
newTarget.AfterTargets = context.EvaluateString (target.AfterTargets);
newTarget.Inputs = context.EvaluateString (target.Inputs);
newTarget.Outputs = context.EvaluateString (target.Outputs);
newTarget.BeforeTargets = context.EvaluateString (target.BeforeTargets);
newTarget.DependsOnTargets = context.EvaluateString (target.DependsOnTargets);
newTarget.Returns = context.EvaluateString (target.Returns);
newTarget.KeepDuplicateOutputs = context.EvaluateString (target.KeepDuplicateOutputs);
project.TargetsIgnoringCondition.Add (newTarget);
if (condIsTrue)
project.Targets.Add (newTarget);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: CreateEvaluatedItem
static MSBuildItemEvaluated CreateEvaluatedItem (MSBuildEvaluationContext context, MSBuildProject project, MSBuildItem sourceItem, string include)
{
var it = new MSBuildItemEvaluated (project, sourceItem.Name, sourceItem.Include, include);
var md = new Dictionary<string,MSBuildPropertyEvaluated> ();
foreach (var c in sourceItem.Metadata.GetProperties ()) {
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;
}