VB.NET EnvDTE最多最新的检查建设项目之前, [英] VB.NET EnvDTE Up-To-Date check before building project

查看:185
本文介绍了VB.NET EnvDTE最多最新的检查建设项目之前,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何检查,如果一个项目是由最新的?

how do I check if a project is up-to-date?

我基本上是试图以编程方式构建列表中的每个项目,但前提是他们已经改变。因此,没有人知道的一种方式(使用EnvDTE也许)检查项目改变,因此需要编写?

I'm basically trying to programmatically build each project in a list but only if they have changed. So does anyone know of a way (using EnvDTE maybe) to check if a project changed and therefore needs to compile?

在此先感谢所有帮助。

Thanks in advance for all the help.

推荐答案

您可以用它做的<一个href="http://msdn.microsoft.com/en-US/library/microsoft.visualstudio.vcprojectengine.vcconfiguration.uptodate.aspx"相对=nofollow> UpToDate的 财产 VCConfiguration

假设你可以得到的一个实例的 EnvDTE.DTE 您可以得到所需要的 VCProjectEngine VCConfiguration 作为活动项目是这样的:

Assuming you can get an instance of EnvDTE.DTE you can get the required VCProjectEngine VCConfiguration for the active project like this:

public Project GetSolutionStartupProject(DTE dte)
{
  string startupProjectName = String.Empty;

  SolutionBuild solutionBuild = dte.Solution.SolutionBuild as SolutionBuild;
  foreach (string item in solutionBuild.StartupProjects as Array)
  {
    startupProjectName += item;
  }

  return dte.Solution.Item(startupProjectName);
}

public void BuildStartupProject(DTE dte)
{
  Project project = GetSolutionStartupProject(dte);
  Configuration activeConfiguration = project.ConfigurationManager.ActiveConfiguration;

  // annoyingly can't just do activeConfiguration.Object as VCConfiguration
  //
  VCProject vcProject = project.Object as VCProject;
  VCConfiguration vcActiveConfiguration = null;
  foreach (VCConfiguration vcConfiguration in vcProject.Configurations)
  {
    if (vcConfiguration.ConfigurationName == activeConfiguration.ConfigurationName &&
        vcConfiguration.Platform.Name == activeConfiguration.PlatformName)
    {
      vcActiveConfiguration= vcConfiguration;
      break;
    }
  }

  if (!vcActiveConfiguration.UpToDate)
  {
    vcActiveConfiguration.Build();
  }
}

如果你想要做的解决方案中的所有项目,那么这将是容易,因为你并不需要找到启动项目。最重要的部分是转换DTE 项目的实例给 VCProjectEngine VCProject ,循环在 VCConfigurations 一旦你做到这一点应该很容易。

If you wanted to do all projects in the solution then it would be easier as you don't need to find the startup project. The important part is converting an instance of DTE Project to a VCProjectEngine VCProject, looping the VCConfigurations once you've done that should be easy.

另外值得一提的是, VCConfiguration.Build()将只建立一个配置,如果相关性尚未建立失败。您可以使用 SolutionBuild.BuildProject() 的建设项目和它的依赖。

Also worth noting that VCConfiguration.Build() will only build that configuration and fail if the dependencies haven't been built. You can use SolutionBuild.BuildProject() to build the project and its dependencies.

这篇关于VB.NET EnvDTE最多最新的检查建设项目之前,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆