2011-04-11 3 views
7

의 내가 하나 개 이상의 프로젝트와 솔루션을 가지고 있다고 가정 해 봅시다, 난 그냥 다음과 같은 방법을 사용하여 빌드를 시작했다했습니다마지막 빌드에서 출력 디렉토리를 얻으려면 어떻게해야합니까?

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

가 어떻게 그냥 내장 된 각 프로젝트의 출력 경로를 얻을 수 있습니다 ? 예를 들어 ...

C : \ MySolution에서 Project1 \ \ 빈 \ 86 \ 릴리스 \
C는 : Project2에 \ 빈 \ 디버그

+0

비슷한 질문 : http://stackoverflow.com/questions/5486593/get-the-macro-value-of-projects-targetpath-via-dte –

답변

9

말하지 마십시오 \ \ MySolution이있다 유일한 방법은 ...

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

이것은 내가 retch하고 싶습니다.

+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

당신은 EnvDTE에서 각 프로젝트의 Built 출력 그룹에서 파일 이름을 통과하여 출력 폴더 (들)을 얻을 수 있습니다 :

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

위대한 작품, 당신은 먼저 구축해야합니다. –

관련 문제