【问题标题】:How do I get the output directories from the last build?如何从上次构建中获取输出目录?
【发布时间】:2011-04-11 19:15:31
【问题描述】:

假设我有一个包含一个或多个项目的解决方案,并且我刚刚使用以下方法开始构建:

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

如何获取每个刚构建的项目的输出路径?比如……

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

【问题讨论】:

标签: build vsx envdte


【解决方案1】:

请不要告诉我这是唯一的方法...

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

这让我想干呕。

【讨论】:

  • 我想说至少有一个"FullOutputPath"。哦,如果想获得最后一个成功的构建,您需要检查 SolutionBuild.LastBuildInfo ,它顺便只显示失败构建的计数。
  • @Terrance:晚安。已经在检查 LBI,但是没有 FullOutputPath。我可以获得 Project.Properties.Item("FullPath") 并将其与 ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath")
  • 我相信这对你来说是古老的历史,但属性 "OutputFileName" 似乎并没有附加到配置,而是附加到项目本身(这是有道理的,因为它不会t 配置之间的变化)。但是为了让我在 VS2015 中使用它,我必须使用 project.Properties.Item("OutputFileName").Value.ToString()
  • 正在寻找那个,帮助了我。一项改进,而不是 'ToString()',我建议始终使用“(string)..”,否则如果 'Value' 返回 'null',您将得到一个异常。
【解决方案2】:

您可以通过遍历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());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 2017-09-20
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 2017-01-06
    相关资源
    最近更新 更多