本文整理汇总了C#中Microsoft.Build.Execution.ProjectInstance.ToProjectItem方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectInstance.ToProjectItem方法的具体用法?C# ProjectInstance.ToProjectItem怎么用?C# ProjectInstance.ToProjectItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Execution.ProjectInstance
的用法示例。
在下文中一共展示了ProjectInstance.ToProjectItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProjects
public IEnumerable<VSProject> GetProjects()
{
List<string> projFilePaths = ExtractProjects(pathToSolutionFile);
var projectItems = new ConcurrentBag<VSProject>();
// let's do sequential for now
//foreach (var pf in projFilePaths)
Parallel.ForEach(projFilePaths, pf =>
{
if (File.Exists(pf))
{
IDictionary<string, string> props = new Dictionary<string, string>();
props.Add("Configuration", "Debug");
props.Add("Platform", "x64");
var projInst = new ProjectInstance(pf, props, "4.0");
var pi = projInst.ToProjectItem();
projectItems.Add(pi);
}
});
return projectItems;
}
示例2: GetProjectReferences
public static List<ProjectCreator.ProjectReference> GetProjectReferences(this ProjectInstance p)
{
var references = new List<ProjectCreator.ProjectReference>();
foreach (var i in p.Items)
{
if (i.ItemType.Equals("ProjectReference"))
{
var proj = i.Metadata.SingleOrDefault(z => z.Name.Equals("Project"));
if (proj != null)
{
references.Add(new ProjectCreator.ProjectReference{
Id=Guid.Parse(proj.EvaluatedValue),
FileName = i.EvaluatedInclude
});
}
else
{
var include = i.EvaluatedInclude;
// try to get physical file and projectguid from that
string dir = Path.GetDirectoryName(p.FullPath);
string projPath = Path.GetFullPath(Path.Combine(dir, include));
if (File.Exists(projPath))
{
var pi = new ProjectInstance(projPath);
var item = pi.ToProjectItem();
references.Add(new ProjectCreator.ProjectReference {Id = item.ProjectGuid, FileName = projPath});
}
else
{
// hack: just don't reference this
//throw new Exception("Project " + p.FullPath + " references non-existent project " + projPath);
}
}
}
}
return references;
}