比方说,我有一个解决方案与一个或多个项目,并使用以下方法我刚刚拉开序幕构建:如何从最后的构建中获取输出目录?
_dte.Solution.SolutionBuild.Build(true); // EnvDTE.DTE
我怎样才能为刚刚建立的每个项目的输出路径?例如...
C:\ MySolution \ PROJECT1 \ BIN \ 86 \发布\
C:\ MySolution \ Project2的\ BIN \调试
比方说,我有一个解决方案与一个或多个项目,并使用以下方法我刚刚拉开序幕构建:如何从最后的构建中获取输出目录?
_dte.Solution.SolutionBuild.Build(true); // EnvDTE.DTE
我怎样才能为刚刚建立的每个项目的输出路径?例如...
C:\ MySolution \ PROJECT1 \ BIN \ 86 \发布\
C:\ MySolution \ Project2的\ BIN \调试
请不要告诉我这是唯一的方法...
// 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。
我想说至少有一个''FullOutputPath''。哦,如果想要获得最后一次成功的构建,您需要检查SolutionBuild.LastBuildInfo,它只会显示失败的构建计数。 – Terrance 2011-04-13 17:49:52
@Terrance:sup。已经检查LBI,但afaik没有FullOutputPath。我可以得到Project.Properties.Item(“FullPath”)并将其与ConfigurationManager.ActiveConfiguration.Properties.Item(“OutputPath”)结合 – Will 2011-04-13 18:25:04
我确定这是古代历史,但属性''OutputFileName“'确实看起来不是附加到配置上,而是附加到项目本身上(这是有道理的,因为它在配置之间不会改变)。但为了让我在VS2015中得到这个工作,我不得不使用'project.Properties.Item(“OutputFileName”)。Value.ToString()'。 – 2016-06-01 15:17:24
您可以通过在EnvDTE的Built
输出组的每个项目在遍历文件名称到输出文件夹(S):
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());
}
这很好,你需要先建立。 – 2015-02-20 07:11:41
类似的问题:http://stackoverflow.com/questions/5486593/getting-the-macro-value-of-projects-targetpath-via-dte – 2011-04-15 23:37:54