2011-04-11 7 views
7

Digamos que tengo una solución con uno o más proyectos, y acabo inició una acumulación usando el siguiente método:¿Cómo obtengo los directorios de salida de la última compilación?

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

¿Cómo puedo obtener las rutas de salida para cada proyecto que acaba de construir ? Por ejemplo ...

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

+0

Pregunta similar: http://stackoverflow.com/questions/5486593/getting-the-macro-value-of-projects-targetpath-via-dte –

Respuesta

9

Por favor, no me diga que esto es la única forma ...

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

Esto me da ganas de vomitar.

+0

Quiero decir que hay un '" FullOutputPath "' como mínimo. Ah, y si quieres obtener la última compilación exitosa, debes consultar SolutionBuild.LastBuildInfo que, por accidente, solo muestra un recuento de compilaciones fallidas. – Terrance

+0

@Terrance: sup. Ya estoy verificando LBI, pero afaik no hay un FullOutputPath. Podría obtener Project.Properties.Item ("FullPath") y combinarlo con ConfigurationManager.ActiveConfiguration.Properties.Item ("OutputPath") – Will

+3

Estoy seguro de que esto es historia antigua para usted, pero la propiedad '" OutputFileName "' no no parece estar unido a la configuración, sino al proyecto en sí (lo cual tiene sentido, ya que no cambiaría entre las configuraciones). Pero para que esto funcione en VS2015, tuve que usar 'project.Properties.Item (" OutputFileName "). Value.ToString()'. –

6

Se puede llegar a la carpeta (s) de salida por la que atraviesa los nombres de los archivos en el grupo Built salida de cada proyecto en 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

Esto funciona muy bien, debes construir primero. –

Cuestiones relacionadas