本文整理汇总了C#中Microsoft.Build.Execution.ProjectInstance.ExpandString方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectInstance.ExpandString方法的具体用法?C# ProjectInstance.ExpandString怎么用?C# ProjectInstance.ExpandString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Execution.ProjectInstance
的用法示例。
在下文中一共展示了ProjectInstance.ExpandString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpandStringWithMetadata
public void ExpandStringWithMetadata ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<ItemGroup>
<Foo Include='xxx'><M>x</M></Foo>
<Foo Include='yyy'><M>y</M></Foo>
</ItemGroup>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.ExpandStringWithMetadata.proj";
var proj = new ProjectInstance (root);
Assert.AreEqual ("xxx;yyy", proj.ExpandString ("@(FOO)"), "#1"); // so, metadata is gone...
}
示例2: GetPropertiesMetadataForProjectReference
/// <summary>
/// The value to be assigned to the metadata for a particular project reference. Contains only configuration and platform specified in the project configuration, evaluated.
/// </summary>
private string GetPropertiesMetadataForProjectReference(ProjectInstance traversalProject, string configurationAndPlatformProperties)
{
string directProjectProperties = traversalProject.ExpandString(configurationAndPlatformProperties);
if (traversalProject.SubToolsetVersion != null)
{
// Note: it is enough below to compare traversalProject.SubToolsetVersion with 4.0 as a means to verify if
// traversalProject.SubToolsetVersion < 12.0 since this path isn't followed for traversalProject.SubToolsetVersion values of 2.0 and 3.5
if (traversalProject.SubToolsetVersion.Equals("4.0", StringComparison.OrdinalIgnoreCase))
{
directProjectProperties = String.Format(CultureInfo.InvariantCulture, "{0}; {1}={2}", directProjectProperties, Constants.SubToolsetVersionPropertyName, traversalProject.SubToolsetVersion);
}
}
return directProjectProperties;
}
示例3: LoadUsingTasks
// FIXME: my guess is the tasks does not have to be loaded entirely but only requested tasks must be loaded at invocation time.
void LoadUsingTasks (ProjectInstance projectInstance, IEnumerable<ProjectUsingTaskElement> usingTasks)
{
Func<string,bool> cond = s => projectInstance != null ? projectInstance.EvaluateCondition (s) : Convert.ToBoolean (s);
Func<string,string> expand = s => projectInstance != null ? projectInstance.ExpandString (s) : s;
foreach (var ut in usingTasks) {
var aName = expand (ut.AssemblyName);
var aFile = expand (ut.AssemblyFile);
if (string.IsNullOrEmpty (aName) && string.IsNullOrEmpty (aFile)) {
var errorNoAssembly = string.Format ("Task '{0}' does not specify either of AssemblyName or AssemblyFile.", ut.TaskName);
engine.LogWarningEvent (new BuildWarningEventArgs (null, null, projectInstance.FullPath, ut.Location.Line, ut.Location.Column, 0, 0, errorNoAssembly, null, null));
continue;
}
var ta = assemblies.FirstOrDefault (a => a.AssemblyFile.Equals (aFile, StringComparison.OrdinalIgnoreCase) || a.AssemblyName.Equals (aName, StringComparison.OrdinalIgnoreCase));
if (ta == null) {
var path = Path.GetDirectoryName (string.IsNullOrEmpty (ut.Location.File) ? projectInstance.FullPath : ut.Location.File);
ta = new TaskAssembly () { AssemblyName = aName, AssemblyFile = aFile };
try {
ta.LoadedAssembly = !string.IsNullOrEmpty (ta.AssemblyName) ? Assembly.Load (ta.AssemblyName) : Assembly.LoadFile (Path.Combine (path, ta.AssemblyFile));
} catch {
var errorNotLoaded = string.Format ("For task '{0}' Specified assembly '{1}' was not found", ut.TaskName, string.IsNullOrEmpty (ta.AssemblyName) ? Path.Combine (path, ta.AssemblyFile) : ta.AssemblyName);
engine.LogWarningEvent (new BuildWarningEventArgs (null, null, projectInstance.FullPath, ut.Location.Line, ut.Location.Column, 0, 0, errorNotLoaded, null, null));
continue;
}
assemblies.Add (ta);
}
var pg = ut.ParameterGroup == null ? null : ut.ParameterGroup.Parameters.Select (p => new TaskPropertyInfo (p.Name, Type.GetType (p.ParameterType), cond (p.Output), cond (p.Required)))
.ToDictionary (p => p.Name);
Type type = null;
string error = null;
TaskDescription task = new TaskDescription () {
TaskAssembly = ta,
Name = ut.TaskName,
TaskFactoryParameters = pg,
TaskBody = ut.TaskBody != null && cond (ut.TaskBody.Condition) ? ut.TaskBody.TaskBody : null,
};
if (string.IsNullOrEmpty (ut.TaskFactory)) {
type = LoadTypeFrom (ta.LoadedAssembly, ut.TaskName, ut.TaskName);
if (type == null)
error = string.Format ("For task '{0}' Specified type '{1}' was not found in assembly '{2}'", ut.TaskName, ut.TaskName, ta.LoadedAssembly.FullName);
else
task.TaskType = type;
} else {
type = LoadTypeFrom (ta.LoadedAssembly, ut.TaskName, ut.TaskFactory);
if (type == null)
error = string.Format ("For task '{0}' Specified factory type '{1}' was not found in assembly '{2}'", ut.TaskName, ut.TaskFactory, ta.LoadedAssembly.FullName);
else
task.TaskFactoryType = type;
}
if (error != null)
engine.LogWarningEvent (new BuildWarningEventArgs (null, null, projectInstance.FullPath, ut.Location.Line, ut.Location.Column, 0, 0, error, null, null));
else
task_descs.Add (task);
}
}