本文整理汇总了C#中Microsoft.Build.Evaluation.Project.ExpandString方法的典型用法代码示例。如果您正苦于以下问题:C# Project.ExpandString方法的具体用法?C# Project.ExpandString怎么用?C# Project.ExpandString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.Project
的用法示例。
在下文中一共展示了Project.ExpandString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDependsOnTargetsAsList
public static IList<string> GetDependsOnTargetsAsList(this ProjectTargetInstance target,Project project)
{
if (target == null) { throw new ArgumentNullException("target"); }
if (project == null) { throw new ArgumentNullException("project"); }
List<string> targets = new List<string>();
string depTargets = target.DependsOnTargets != null ? target.DependsOnTargets : string.Empty;
string depTargetsEvaluated = project.ExpandString(depTargets);
string[] dtArray = depTargetsEvaluated.Split(';');
dtArray.ToList().ForEach(t => {
if (!string.IsNullOrWhiteSpace(t)) {
string tName = t.Trim();
if (!string.IsNullOrWhiteSpace(tName) &&
string.Compare(";", tName, StringComparison.InvariantCultureIgnoreCase) != 0) {
targets.Add(tName);
}
}
});
int numTarges = targets != null ? targets.Count() : 0;
string tempDebug = null;
if (numTarges >= 1) {
tempDebug = targets[0];
}
return targets;
}
示例2: MSBuildUsing
public MSBuildUsing(Project project, ProjectUsingTaskElement pute)
{
FileInfo f = new FileInfo(pute.TaskName);
this.Name = f.Name;
this.AssemblyFile = pute.AssemblyFile;
this.TaskFactory = pute.TaskFactory;
this.Source = project.ExpandString(pute.AssemblyFile);
}
示例3: MSBuildTarget
public MSBuildTarget(ProjectTargetInstance pti, Project project, MSBuildFile parent = null)
{
this.Target = pti;
this.Name = pti.Name;
this.Inputs = pti.Inputs;
this.Outputs = pti.Outputs;
this.Location = pti.FullPath;
this.DependsOnTargets = pti.DependsOnTargets;
this.TargetColor = "Black";
this.FontStyle = "Normal";
if (!string.IsNullOrEmpty(this.Target.Condition))
{
this.TargetCondition = this.Target.Condition;
this.TargetColor = "Gray";
this.FontStyle = "Italic";
}
if (project.Xml.DefaultTargets.Contains(pti.Name))
{
this.TargetColor = "MediumBlue";
}
if (project.Xml.InitialTargets.Contains(pti.Name))
{
this.TargetColor = "LimeGreen";
}
if (project.Xml.InitialTargets.Contains(pti.Name) && project.Xml.DefaultTargets.Contains(pti.Name))
{
this.TargetColor = "Gold";
}
this.Targets = new ObservableCollection<MSBuildTarget>();
string targets = project.ExpandString(pti.DependsOnTargets);
targets = this.formatRegex.Replace(targets, string.Empty);
int i = 0;
foreach (var target in targets.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
this.Targets.Add(new MSBuildTarget(target));
i++;
}
foreach (var x in project.Xml.Targets.Where(x => x.Name == pti.Name))
{
this.BeforeTargets = x.BeforeTargets;
this.AfterTargets = x.AfterTargets;
}
if (parent != null)
{
this.Parent = parent;
}
}
示例4: ProjectToJson
private static JObject ProjectToJson(Project project)
{
JObject jsonProject = new JObject();
// Project items like resources, sources and references
foreach (var item in project.ItemsIgnoringCondition)
{
if (jsonProject[item.ItemType] == null)
{
jsonProject[item.ItemType] = new JArray();
}
JArray array = (JArray)jsonProject[item.ItemType];
var jsonItem = new JObject();
jsonItem["Include"] = item.EvaluatedInclude;
foreach (var metaData in item.Metadata)
{
jsonItem[metaData.Name] = metaData.EvaluatedValue;
}
array.Add(jsonItem);
}
// Project properties
JObject jsonProperties = new JObject();
foreach (var property in project.AllEvaluatedProperties)
{
var value = project.ExpandString(property.EvaluatedValue);
// Multiple values
if (value.Contains(";") && value.Contains("\n"))
{
var values = value
.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Where(v => !string.IsNullOrWhiteSpace(v))
.Select(v => v.Trim());
JArray jsonValueArray = new JArray();
foreach (var v in values)
{
jsonValueArray.Add(v);
}
jsonProperties[property.Name] = jsonValueArray;
}
else
{
jsonProperties[property.Name] = value.Trim();
}
}
jsonProject["Properties"] = jsonProperties;
return jsonProject;
}
示例5: ExpandString
public void ExpandString ()
{
string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<Foo>What are 'ESCAPE' & ""EVALUATE"" ? $ # % ^</Foo>
<Bar>y</Bar>
<Baz Condition=""$(Void)==''"">$(FOO)</Baz>
</PropertyGroup>
</Project>";
var reader = XmlReader.Create (new StringReader (xml));
var root = ProjectRootElement.Create (reader);
var proj = new Project (root);
root.FullPath = "ProjectTest.ExpandString.proj";
Assert.AreEqual ("xyz", proj.ExpandString ("x$(BAR)z"), "#1");
Assert.AreEqual ("x$(BARz", proj.ExpandString ("x$(BARz"), "#2"); // incomplete
Assert.AreEqual ("xz", proj.ExpandString ("[email protected](BAR)z"), "#3"); // not an item
}
示例6: BuildTargetGraph
protected internal AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>> BuildTargetGraph(Project project)
{
AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>> graph =
new AdjacencyGraph<ProjectTargetInstance, Edge<ProjectTargetInstance>>();
foreach (string key in project.Targets.Keys) {
var target = project.Targets[key];
if (!graph.ContainsVertex(target)) {
graph.AddVertex(target);
}
// TODO: DependsOnTargets needs to be evalueated
string depTargetsString = target.DependsOnTargets != null ? target.DependsOnTargets : string.Empty;
List<string> dependentTargets = target.GetDependsOnTargetsAsList(project).ToList();
string depTargetsStringEvaluated = project.ExpandString(depTargetsString);
dependentTargets.ToList().ForEach(depTarget => {
var dt = project.Targets[depTarget];
if (dt != null) {
if (!graph.ContainsVertex(dt)) {
graph.AddVertex(dt);
}
Edge<ProjectTargetInstance> e = new Edge<ProjectTargetInstance>(target, dt);
graph.AddEdge(e);
}
});
}
return graph;
}