2011-04-11 3 views
7

Скажем, у меня есть решение с одним или несколькими проектами, и я только что стартовал сборки, используя следующий метод:Как получить выходные каталоги из последней сборки?

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

Как я могу получить выходные пути для каждого проекта, который только что создали ? Например ...

C: \ MySolution \ Проект1 \ Bin \ x86 \ Release \
C: \ MySolution \ Проект2 \ Bin \ Debug

+0

Похожий вопрос: http://stackoverflow.com/questions/5486593/get-the-macro-value-of-projects-targetpath-via-dte –

ответ

9

Пожалуйста, не говори мне, что это единственный способ ...

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

Это заставляет меня хотеть переделать.

+0

Я хочу сказать, что есть '' FullOutputPath'', по крайней мере. О, и если вы хотите получить последнюю успешную сборку, вы хотите проверить версию SolutionBuild.LastBuildInfo, которая, по-видимому, показывает только количество неудачных сборок. – Terrance

+0

@ Полностью: sup. Уже проверяем LBI, но у afaik нет FullOutputPath. Я мог бы получить Project.Properties.Item («FullPath») и объединить его с ConfigurationManager.ActiveConfiguration.Properties.Item («OutputPath») – Will

+3

Я уверен, что это древняя история для вас, но свойство '' OutputFileName '' как представляется, не привязаны к конфигурации, а скорее к самому проекту (что имеет смысл, поскольку оно не изменилось бы между конфигурациями). Но для того, чтобы заставить эту работу работать в VS2015, мне пришлось использовать 'project.Properties.Item (« OutputFileName »). Value.ToString()'. –

6

Вы можете получить в папку вывода (ов) путем обхода имен файлов в Built группы выходов каждого проекта в 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

Это отлично работает, вам нужно построить в первую очередь. –