本文整理汇总了C#中Microsoft.Build.Evaluation.ProjectCollection.GetLoadedProjects方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectCollection.GetLoadedProjects方法的具体用法?C# ProjectCollection.GetLoadedProjects怎么用?C# ProjectCollection.GetLoadedProjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.ProjectCollection
的用法示例。
在下文中一共展示了ProjectCollection.GetLoadedProjects方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFile
internal static MSBuildFile GetFile(FileInfo file)
{
using (ProjectCollection loadedProjects = new ProjectCollection())
{
Project currentProject = loadedProjects.GetLoadedProjects(file.FullName).FirstOrDefault();
if (currentProject != null)
{
loadedProjects.UnloadProject(currentProject);
}
loadedProjects.LoadProject(file.FullName);
currentProject = loadedProjects.GetLoadedProjects(file.FullName).FirstOrDefault();
MSBuildFile m = new MSBuildFile(currentProject);
if (currentProject.Targets != null)
{
SortedDictionary<string, ProjectTargetInstance> sortedTargets = new SortedDictionary<string, ProjectTargetInstance>(currentProject.Targets);
foreach (var t in sortedTargets)
{
ProjectTargetInstance pti = t.Value;
m.Targets.Add(new MSBuildTarget(pti, currentProject, m));
}
}
foreach (var us in currentProject.Xml.UsingTasks)
{
m.Usings.Add(new MSBuildUsing(currentProject, us));
}
foreach (ResolvedImport import in currentProject.Imports)
{
m.Imports.Add(new MSBuildImport(import));
}
foreach (var property in currentProject.Properties)
{
m.Properties.Add(new MSBuildProperties(property));
}
if (currentProject.AllEvaluatedItems != null)
{
foreach (var item in currentProject.AllEvaluatedItems)
{
m.Items.Add(new MSBuildItems(item.ItemType, item.UnevaluatedInclude, item.EvaluatedInclude, item.IsImported));
}
}
return m;
}
}
示例2: ProjectProcessor
public ProjectProcessor(string path)
{
using (ProjectCollection pc = new ProjectCollection())
{
this.Project = pc.GetLoadedProjects(path).FirstOrDefault();
}
}
示例3: GetLoadedProjectsWithoutFullPath
public void GetLoadedProjectsWithoutFullPath ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
string path = Path.GetFullPath ("foo.xml");
var pc = new ProjectCollection ();
pc.LoadProject (XmlReader.Create (new StringReader (project_xml), null, path));
Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#1"); // huh?
Assert.AreEqual (0, pc.LoadedProjects.Count, "#1.1");
new Project (root, null, null, pc);
Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#2"); // huh?
}
示例4: GetLoadedProjectsForProjectInstance
public void GetLoadedProjectsForProjectInstance ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
string path = Path.GetFullPath ("foo.xml");
var pc = new ProjectCollection ();
root.FullPath = "foo.xml";
new ProjectInstance (root, null, null, pc);
Assert.AreEqual (0, pc.GetLoadedProjects (path).Count, "#1"); // so, ProjectInstance does not actually load Project...
}
示例5: GetLoadedProjectsSuccess2
public void GetLoadedProjectsSuccess2 ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
string path = Path.GetFullPath ("GetLoadedProjectsSuccess2.xml");
var pc = new ProjectCollection ();
using (var fs = File.CreateText (path))
fs.Write (project_xml);
try {
var proj = pc.LoadProject (path);
Assert.AreEqual (1, pc.GetLoadedProjects (path).Count, "#1"); // ok... LoadProject (with filename) adds it to the collection.
Assert.AreEqual (proj, pc.GetLoadedProjects (path).First (), "#2");
} finally {
File.Delete (path);
}
}
示例6: GetLoadedProjectsSuccess
public void GetLoadedProjectsSuccess ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
string path = Path.GetFullPath ("foo.xml");
var pc = new ProjectCollection ();
var proj = new Project (root, null, null, pc);
// this order also matters for test; It sets FullPath after Project.ctor(), and should still work.
root.FullPath = "foo.xml";
Assert.AreEqual (1, pc.GetLoadedProjects (path).Count, "#1"); // wow ok...
Assert.AreEqual (proj, pc.GetLoadedProjects (path).First (), "#2");
}
示例7: AddProjectReferenceDependencies
/// <summary>
/// Adds referenced projects that have corresponding nuspec files as dependencies.
/// </summary>
/// <param name="dependencies">The dependencies collection where the new dependencies
/// are added into.</param>
private void AddProjectReferenceDependencies(Dictionary<string, PackageDependency> dependencies)
{
var processedProjects = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var projectsToProcess = new Queue<Project>();
using (var projectCollection = new ProjectCollection())
{
projectsToProcess.Enqueue(_project);
while (projectsToProcess.Count > 0)
{
var project = projectsToProcess.Dequeue();
processedProjects.Add(project.FullPath);
foreach (var projectReference in project.GetItems(ProjectReferenceItemType))
{
string fullPath = projectReference.GetMetadataValue("FullPath");
if (string.IsNullOrEmpty(fullPath) ||
processedProjects.Contains(fullPath))
{
continue;
}
var loadedProjects = projectCollection.GetLoadedProjects(fullPath);
var referencedProject = loadedProjects.Count > 0 ?
loadedProjects.First() :
new Project(
fullPath,
globalProperties: project.GlobalProperties,
toolsVersion: null,
projectCollection: projectCollection);
if (NuspecFileExists(fullPath))
{
var dependency = CreateDependencyFromProject(referencedProject);
dependencies[dependency.Id] = dependency;
}
else
{
projectsToProcess.Enqueue(referencedProject);
}
}
}
}
}
示例8: RecursivelyApply
/// <summary>
/// Recursively execute the specified action on the current project and
/// projects referenced by the current project.
/// </summary>
/// <param name="action">The action to be executed.</param>
/// <param name="alreadyAppliedProjects">The collection of projects that have been processed.
/// It is used to avoid processing the same project more than once.</param>
private void RecursivelyApply(Action<ProjectFactory> action, ProjectCollection alreadyAppliedProjects)
{
action(this);
foreach (var item in _project.GetItems(ProjectReferenceItemType))
{
string fullPath = item.GetMetadataValue("FullPath");
if (!string.IsNullOrEmpty(fullPath) &&
!NuspecFileExists(fullPath) &&
alreadyAppliedProjects.GetLoadedProjects(fullPath).IsEmpty())
{
var project = new Project(
fullPath,
globalProperties: null,
toolsVersion: null,
projectCollection: alreadyAppliedProjects);
var referencedProject = new ProjectFactory(project);
referencedProject.Logger = _logger;
referencedProject.IncludeSymbols = IncludeSymbols;
referencedProject.Build = Build;
referencedProject.IncludeReferencedProjects = IncludeReferencedProjects;
referencedProject.ProjectProperties = ProjectProperties;
referencedProject.TargetFramework = TargetFramework;
referencedProject.BaseTargetPath = BaseTargetPath;
referencedProject.SolutionName = SolutionName;
referencedProject.BuildProject();
referencedProject.RecursivelyApply(action, alreadyAppliedProjects);
}
}
}
示例9: LoadFile
private void LoadFile(FileInfo file)
{
try
{
using (ProjectCollection loadedProjects = new ProjectCollection())
{
this.proj = loadedProjects.GetLoadedProjects(file.FullName).FirstOrDefault();
if (this.proj != null)
{
loadedProjects.UnloadProject(this.proj);
}
loadedProjects.LoadProject(file.FullName);
this.proj = loadedProjects.GetLoadedProjects(file.FullName).FirstOrDefault();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Parsing Text", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
示例10: InitializeMsBuildProject
/// <summary>
/// Initializes the in memory project. Sets BuildEnabled on the project to true.
/// </summary>
/// <param name="engine">The build engine to use to create a build project.</param>
/// <param name="fullProjectPath">The full path of the project.</param>
/// <returns>A loaded msbuild project.</returns>
internal static Microsoft.Build.Evaluation.Project InitializeMsBuildProject(ProjectCollection buildEngine, string fullProjectPath)
{
ArgumentNotNullOrEmpty("fullProjectPath", fullProjectPath);
// Call GetFullPath to expand any relative path passed into this method.
fullProjectPath = CommonUtils.NormalizePath(fullProjectPath);
// Check if the project already has been loaded with the fullProjectPath. If yes return the build project associated to it.
var loadedProject = new List<Microsoft.Build.Evaluation.Project>(buildEngine.GetLoadedProjects(fullProjectPath));
Microsoft.Build.Evaluation.Project buildProject = loadedProject != null && loadedProject.Count > 0 && loadedProject[0] != null ? loadedProject[0] : null;
if (buildProject == null)
{
buildProject = buildEngine.LoadProject(fullProjectPath);
}
return buildProject;
}