public Core() { Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Start Core(): {0}", this.ToString())); //SolutionEventsListener class from http://stackoverflow.com/questions/2525457/automating-visual-studio-with-envdte // via Elisha http://stackoverflow.com/users/167149/elisha SolutionEventsListener = new SolutionEventsListener(); SolutionEventsListener.OnQueryUnloadProject += () => { CopiedFiles.RemoveAll(); }; Dte = Package.GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2; Events = Dte.Events as Events2; var docEvents = Events.DocumentEvents; var projectEvents = Events.ProjectItemsEvents; var buildEvents = Events.BuildEvents; _events.Add(docEvents); _events.Add(projectEvents); _events.Add(buildEvents); docEvents.DocumentSaved += FileHandler.ItemSaved; projectEvents.ItemAdded += FileHandler.ItemAdded; projectEvents.ItemRemoved += FileHandler.ItemRemoved; projectEvents.ItemRenamed += FileHandler.ItemRenamed; buildEvents.OnBuildBegin += BuildHandler.BuildBegin; buildEvents.OnBuildDone += BuildHandler.BuildDone; }
public static void BuildDone(vsBuildScope buildScope, vsBuildAction buildAction) { Trace.WriteLine("Build done"); // Once the project has built then try and clean up the files copied into the Bootstrapper CopiedFiles.RemoveAll(); }
public static void ItemRemoved(ProjectItem projectItem) { CopiedFiles.Remove(projectItem.FilenameAsRelativePath()); //var startupProject = Infrastructure.Core.Instance.StartupProject; //var existingFile = startupProject.Combine(projectItem.FilenameAsRelativePath()); //if (File.Exists(existingFile)) //File.Delete(existingFile); }
public static void ItemRenamed(ProjectItem projectItem, string oldName) { // Write the new file to disk and clean up the old. ItemAdded(projectItem); // Remove the old file, so we need to sub out the name name with the old. var oldRelativeFilePath = projectItem.FilenameAsRelativePath().Replace(Path.GetFileName(projectItem.FileNames[0]), oldName); CopiedFiles.Remove(oldRelativeFilePath); //var startupProject = Infrastructure.Core.Instance.StartupProject; //var existingFile = startupProject.Combine(projectItem.FilenameAsRelativePath()); //var old = Path.Combine(Path.GetDirectoryName(existingFile), oldName); //if (File.Exists(old)) //File.Delete(old); }
public static void ItemAdded(ProjectItem projectItem) { if (projectItem.Properties == null) { return; } // Troubles loading F# projects. if (projectItem.GetType().ToString().Equals("Microsoft.VisualStudio.FSharp.ProjectSystem.Automation.OAFileItem", StringComparison.InvariantCultureIgnoreCase)) { return; } // Only try and copy physical files (ignore folders, sub projects, virtual files. if (Guid.Parse(projectItem.Kind) != Guid.Parse("6bb5f8ee-4483-11d3-8bcf-00c04f8ec28c")) // GUID_ItemType_PhysicalFile { return; } var isPermittedFileType = FuncEx.Create((List <string> fileTypes, ProjectItemBuildAction action) => { if (!fileTypes.Contains(Path.GetExtension(projectItem.Name).TrimStart('.'))) { return(false); } var buildAction = (ProjectItemBuildAction)projectItem.Properties.Item("BuildAction").Value; if (buildAction != action) { return(false); } return(true); }); if (!(isPermittedFileType(EmbeddedResourceFileTypes, ProjectItemBuildAction.EmbeddedResource) || isPermittedFileType(ContentFileTypes, ProjectItemBuildAction.Content))) { return; } // If this is a cshtml file then check to see if it has a customtool property value. If there's no value then the cshtml file // is probably coming from a theme and shouldn't be copied at all. if (Path.GetExtension(projectItem.Name).Equals(".cshtml", StringComparison.InvariantCultureIgnoreCase)) { if (projectItem.FileNames[0].ToLower().Contains("app_code")) { return; } string customTool = projectItem.Properties.Item("CustomTool").Value.ToString(); if (String.IsNullOrEmpty(customTool)) { return; } } // If the file belongs to the start up application don't copy it anywhere var startupProject = Infrastructure.Core.Instance.StartupProject; if (projectItem.ContainingProject.Equals(startupProject)) { return; } CopiedFiles.Add(startupProject, projectItem); var ie = projectItem.ProjectItems.GetEnumerator(); while (ie.MoveNext()) { ProjectItem subProjectItem = projectItem.ProjectItems.Item(((dynamic)ie.Current).Name); ItemAdded(subProjectItem); } // Copy the file from the project into the same folder structure under the Startup Application // Have to be careful to keep folders like /content/styles/cool.css //var saveTo = startupProject.Combine(projectItem.FilenameAsRelativePath()); //if (!Directory.Exists(Path.GetDirectoryName(saveTo))) // Directory.CreateDirectory(Path.GetDirectoryName(saveTo)); //File.Copy(projectItem.FileNames[0], saveTo, true); //Infrastructure.Core.Instance.Notity("Embedded resource exported to " + saveTo); }
int IVsSolutionEvents.OnAfterCloseSolution(object pUnkReserved) { CopiedFiles.RemoveAll(); return(VSConstants.S_OK); }