public override void ProjectFinishedGenerating(Project project) { base.ProjectFinishedGenerating(project); var vs = project.DTE; if (vs != null) { using (var serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)vs)) { TraceSourceExtensions.ShieldUI(tracer, (Action)(() => { var solution = serviceProvider.GetService <ISolution>(); var projectAdded = solution.Find <IProject>(p => p.As <Project>().UniqueName == project.UniqueName).FirstOrDefault(); var items = projectAdded.Find <IItem>(item => item.As <ProjectItem>() != null); foreach (var item in items) { if (!string.IsNullOrEmpty(item.Data.CustomTool)) { var runCustomToolOnUnfold = item.Data.RunCustomToolOnUnfold; if (!string.IsNullOrEmpty(runCustomToolOnUnfold)) { bool runTool = false; Boolean.TryParse(runCustomToolOnUnfold, out runTool); if (!runTool) { continue; } } var projectItem = item.As <ProjectItem>().Object as VSProjectItem; if (projectItem != null) { tracer.Info(Resources.CustomToolRunnerTemplateWizard_RunningCustomTool, ((object)item.Data.CustomTool).ToString(), item.GetLogicalPath()); projectItem.RunCustomTool(); } } } }), Resources.CustomToolRunnerTemplateWizard_FailedToRunCustomTools); } } }
public override void RunFinished() { base.RunFinished(); if (this.dte != null) { using (var serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider) this.dte)) { TraceSourceExtensions.ShieldUI(tracer, (Action)(() => { var projects = dte.Solution.Projects .OfType <Project>() .Where(p => !string.IsNullOrEmpty(p.FullName)); foreach (var project in projects) { var fileInfo = new FileInfo(project.FullName); var projectBuilder = Microsoft.Build.Construction.ProjectRootElement.Open(fileInfo.FullName); var projectEvaluated = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects .FirstOrDefault <Microsoft.Build.Evaluation.Project>(p => p.FullPath.Equals(fileInfo.FullName, StringComparison.InvariantCultureIgnoreCase)); if (projectBuilder != null && projectEvaluated != null) { var items = projectBuilder.Items.Where(i => i.Metadata.Any(m => m.Name == Link) && i.Metadata.Any(m => m.Name == FixedLink)); if (items.Any()) { // Suspend project file change notifications var fileChange = serviceProvider.GetService <SVsFileChangeEx, IVsFileChangeEx>(); uint cookie = 0; if (fileChange != null) { Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(cookie, fileInfo.FullName, 1)); } foreach (var item in items) { // Ensure we have a fixed link property var fixedLink = item.Metadata.First(m => m.Name == FixedLink); if (fixedLink != null && !String.IsNullOrEmpty(fixedLink.Value)) { // Ensure we have an Include attribute if (!string.IsNullOrEmpty(item.Include)) { item.Include = fixedLink.Value; fixedLink.Value = string.Empty; tracer.Verbose(Resources.FixLinkPathTemplateWizard_LinkFixed, item.Label, fixedLink.Value); } // TODO: Remove fixed link (cant do this, collection is readonly) ////item.Metadata.Remove(fixedLink); } } projectBuilder.Save(); // Resume project file change notifications if (fileChange != null) { Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(fileChange.SyncFile(fileInfo.FullName)); Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(fileChange.IgnoreFile(cookie, fileInfo.FullName, 0)); project.ReloadProject(); } } } } }), Resources.FixLinkPathTemplateWizard_FailedToFixLinkPaths); } } }