2011-04-11 15 views
7

Diciamo che ho una soluzione con uno o più progetti, e ho appena dato il via una build utilizzando il seguente metodo:Come ottengo le directory di output dall'ultima build?

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

Come posso ottenere i percorsi di uscita per ciascun progetto che appena costruito ? Per esempio ...

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

+0

domanda simile: http://stackoverflow.com/questions/5486593/get-the-macro-value-of-projects-targetpath-via-dte –

risposta

9

Per favore non mi dica questo è l'unico modo ...

// 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); 
} 

Questo mi fa venire voglia di vomitare.

+0

Voglio dire che c'è un '' FullOutputPath ''per lo meno. Oh e se vuoi ottenere l'ultima build di successo vuoi controllare il SolutionBuild.LastBuildInfo che mostra solo incidentalmente un conteggio di build falliti. – Terrance

+0

@Terrance: sup. Sto già controllando LBI, ma dopo non c'è un FullOutputPath. Potrei ottenere Project.Properties.Item ("FullPath") e combinarlo con ConfigurationManager.ActiveConfiguration.Properties.Item ("OutputPath") – Will

+3

Sono sicuro che questa è una storia antica per te, ma la proprietà '" OutputFileName "' non non sembra essere collegato alla configurazione, ma piuttosto al progetto stesso (che ha senso, dal momento che non cambierebbe tra le configurazioni). Ma per far funzionare questo in VS2015, ho dovuto usare 'project.Properties.Item (" OutputFileName "). Value.ToString()'. –

6

Si può raggiungere la cartella di output (s) attraversando i nomi dei file nel gruppo Built uscita di ogni progetto 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()); 
} 
+0

Funziona alla grande, devi prima costruire. –

Problemi correlati