How do I get the output directories from the last build?
Asked Answered
E

2

8

Let's say I've got a solution with one or more projects, and I've just kicked off a build using the following method:

_dte.Solution.SolutionBuild.Build(true); // EnvDTE.DTE

How can I get the output paths for each project that just built? For example...

c:\MySolution\Project1\Bin\x86\Release\
c:\MySolution\Project2\Bin\Debug

Eliathan answered 11/4, 2011 at 19:15 Comment(1)
Similar question: #5487093Balmacaan
E
11

Please don't tell me this is the only way...

// dte is my wrapper; dte.Dte is EnvDte.DTE               
var ctxs = dte.Dte.Solution.SolutionBuild.ActiveConfiguration
              .SolutionContexts.OfType<SolutionContext>()
              .Where(x => x.ShouldBuild == true);
var temp = new List<string>(); // output filenames
// oh shi
foreach (var ctx in ctxs)
{
    // sorry, you'll have to OfType<Project>() on Projects (dte is my wrapper)
    // find my Project from the build context based on its name.  Vomit.
    var project = dte.Projects.First(x => x.FullName.EndsWith(ctx.ProjectName));
    // Combine the project's path (FullName == path???) with the 
    // OutputPath of the active configuration of that project
    var dir = System.IO.Path.Combine(
                        project.FullName,
                        project.ConfigurationManager.ActiveConfiguration
                        .Properties.Item("OutputPath").Value.ToString());
    // and combine it with the OutputFilename to get the assembly
    // or skip this and grab all files in the output directory
    var filename = System.IO.Path.Combine(
                        dir,
                        project.ConfigurationManager.ActiveConfiguration
                        .Properties.Item("OutputFilename").Value.ToString());
    temp.Add(filename);
}

This makes me want to retch.

Eliathan answered 11/4, 2011 at 20:5 Comment(4)
I wanna say there is a "FullOutputPath" at the very least. Oh and if wanting to get the last successful build you wanna check the SolutionBuild.LastBuildInfo which incidently only shows a count of failed builds.Lunulate
@Terrance: sup. Already checking LBI, but afaik there isn't a FullOutputPath. I could get Project.Properties.Item("FullPath") and combine it with ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath")Eliathan
I'm sure this is ancient history for you, but the property "OutputFileName" does not appear to be attached to the configuration, but rather to the project itself (which makes sense, since it wouldn't change between configurations). But in order for me to get this working in VS2015, I had to use project.Properties.Item("OutputFileName").Value.ToString().Corella
Was looking for that, helped me. One improvement, instead of 'ToString()' I recommend always using "(string).." or you will get an exception if 'Value' would return 'null'.Lichfield
T
6

You can get to the output folder(s) by traversing the file names in the Built output group of each project in EnvDTE:

var outputFolders = new HashSet<string>();
var builtGroup = project.ConfigurationManager.ActiveConfiguration.OutputGroups.OfType <EnvDTE.OutputGroup>().First(x => x.CanonicalName == "Built");

foreach (var strUri in ((object[])builtGroup.FileURLs).OfType<string>())
{
  var uri = new Uri(strUri, UriKind.Absolute);
  var filePath = uri.LocalPath;
  var folderPath = Path.GetDirectoryName(filePath);
  outputFolders.Add(folderPath.ToLower());
}
Tackett answered 26/2, 2014 at 23:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.