Preliminary validation of VB.NET EnvDTE before construction project

How to check if the project is updated?

I basically try to programmatically build each project in a list, but only if they have changed. So does anyone know a way (using EnvDTE, perhaps) to check if the project has changed and therefore needs to be compiled?

Thanks in advance for your help.

+4
source share
2 answers

Use the EnvDTE.Document interface:

Document d = //get document bool saved = d.Saved; 

The saved property will be false if the document is dirty.

0
source

You can do this using the UpToDate VCConfiguration property.

Assuming you can get an instance of EnvDTE.DTE , you can get the required VCProjectEngine VCConfiguration for the active project as follows: p>

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

If you want to make all the projects in a solution, it will be easier, since you do not need to look for a launch project. The important part is the conversion of the DTE Project instance to VCProjectEngine VCProject , looping VCConfigurations after you have it easy.

It is also worth noting that VCConfiguration.Build () will only build this configuration and crash if dependencies have not been created. You can use SolutionBuild.BuildProject () to create a project and its dependencies.

0
source

All Articles