Skip to content

Instantly share code, notes, and snippets.

@Insire
Forked from Cryental/getallrefs.cs
Created February 8, 2020 18:03
Show Gist options
  • Select an option

  • Save Insire/c0043bd02a069c735a56fac7cbbac0b0 to your computer and use it in GitHub Desktop.

Select an option

Save Insire/c0043bd02a069c735a56fac7cbbac0b0 to your computer and use it in GitHub Desktop.

Revisions

  1. @Cryental Cryental revised this gist Feb 8, 2020. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions getallrefs.cs
    Original file line number Diff line number Diff line change
    @@ -20,10 +20,5 @@ private static string[] PrintResultItems(BuildResult result, string targetName)
    var buildResult = result.ResultsByTarget[targetName];
    var buildResultItems = buildResult.Items;

    if (buildResultItems.Length == 0)
    {
    return new string[0] { };
    }

    return buildResultItems.Select(item => item.ItemSpec).ToArray();
    return buildResultItems.Length == 0 ? new string[0] { } : buildResultItems.Select(item => item.ItemSpec).ToArray();
    }
  2. @Cryental Cryental revised this gist Feb 8, 2020. 1 changed file with 1 addition and 7 deletions.
    8 changes: 1 addition & 7 deletions getallrefs.cs
    Original file line number Diff line number Diff line change
    @@ -25,11 +25,5 @@ private static string[] PrintResultItems(BuildResult result, string targetName)
    return new string[0] { };
    }

    var items = new List<string>();
    foreach (var item in buildResultItems)
    {
    items.Add(item.ItemSpec);
    }

    return items.ToArray();
    return buildResultItems.Select(item => item.ItemSpec).ToArray();
    }
  3. @Cryental Cryental created this gist Feb 8, 2020.
    35 changes: 35 additions & 0 deletions getallrefs.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    private static List<string> GetAllReferences(string fullPath)
    {
    var logger = new ConsoleLogger(LoggerVerbosity.Quiet);
    var manager = BuildManager.DefaultBuildManager;

    var projectInstance = new ProjectInstance(fullPath);
    var result = manager.Build(new BuildParameters {DetailedSummary = false, Loggers = new List<ILogger> {logger}}, new BuildRequestData(projectInstance, new[] {"ResolveProjectReferences", "ResolveAssemblyReferences"}));

    var items1 = PrintResultItems(result, "ResolveProjectReferences");
    var items2 = PrintResultItems(result, "ResolveAssemblyReferences");

    var allItems = items1.ToList();
    allItems.AddRange(items2);

    return allItems;
    }

    private static string[] PrintResultItems(BuildResult result, string targetName)
    {
    var buildResult = result.ResultsByTarget[targetName];
    var buildResultItems = buildResult.Items;

    if (buildResultItems.Length == 0)
    {
    return new string[0] { };
    }

    var items = new List<string>();
    foreach (var item in buildResultItems)
    {
    items.Add(item.ItemSpec);
    }

    return items.ToArray();
    }