private bool AddItem(SvnItem item, out uint parentId) { ThreadHelper.ThrowIfNotOnUIThread(); string itemDir = item.Directory; if (itemDir == null) { parentId = VSItemId.Nil; return(false); } else if (string.Equals(itemDir, ProjectDirectory, StringComparison.OrdinalIgnoreCase)) { parentId = VSItemId.Root; } else { parentId = GetId(itemDir, VSItemId.Root); if (parentId == VSItemId.Nil) { if (!AddItem(item.Parent, out parentId)) { return(false); } parentId = GetId(itemDir, parentId); if (parentId == VSItemId.Nil) { return(false); } } } VSADDRESULT[] result = new VSADDRESULT[1]; return(VSErr.Succeeded(VsProject.AddItem(parentId, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, item.FullPath, 1, new string[] { item.FullPath }, IntPtr.Zero, result)) && result[0] == VSADDRESULT.ADDRESULT_Success); }
int IVsSingleFileGenerator.Generate(string InputFilePath, string InputFileContents, string DefaultNamespace, IntPtr[] OutputFileContents, out uint Output, IVsGeneratorProgress GenerateProgress) { byte[] bOutputFileContents = GenerateCode(InputFileContents, InputFilePath, GenerateProgress); string szOutputFilePath = InputFilePath.Replace(Path.GetExtension(InputFilePath), _Ext); if (bOutputFileContents != null) { uint nItemId; uint nMinItemId; VSADDRESULT[] oAddResult = new VSADDRESULT[1]; FileStream oOutputFile = File.Create(szOutputFilePath); oOutputFile.Write(bOutputFileContents, 0, bOutputFileContents.Length); oOutputFile.Close( ); nItemId = GetProjectItemId(InputFilePath); if (VsProject.AddItem(nItemId, VSADDITEMOPERATION.VSADDITEMOP_OPENFILE, szOutputFilePath, 1, new string[] { szOutputFilePath }, IntPtr.Zero, oAddResult) == VSConstants.S_OK) { nMinItemId = GetProjectItemId(szOutputFilePath); Microsoft.Build.Evaluation.ProjectItem oItem = GetProjectItem(InputFilePath); Microsoft.Build.Evaluation.ProjectItem oMinItem = GetProjectItem(szOutputFilePath); VsBuildPropertyStorage.SetItemAttribute(nItemId, "LastGenOutput", Path.GetFileName(szOutputFilePath)); VsBuildPropertyStorage.SetItemAttribute(nMinItemId, "AutoGen", "True"); VsBuildPropertyStorage.SetItemAttribute(nMinItemId, "DesignTime", "True"); VsBuildPropertyStorage.SetItemAttribute(nMinItemId, "DependentUpon", Path.GetFileName(InputFilePath)); switch (OptionPage.CompileTargetType) { case CompileTargetType.Default: { oItem.Xml.Condition = string.Empty; oMinItem.Xml.Condition = string.Empty; } break; case CompileTargetType.Mixed: { oItem.Xml.Condition = " '$(Configuration)' == 'Debug' "; oMinItem.Xml.Condition = " '$(Configuration)' == 'Release' "; } break; } switch (OptionPage.BuildActionType) { case BuildActionType.Copy: { oMinItem.ItemType = oItem.ItemType; } break; case BuildActionType.Custom: { oItem.ItemType = OptionPage.OriginalBuildAction; oMinItem.ItemType = OptionPage.MinifiedBuildAction; } break; } ////////////////////// Application.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate( ); Application.ToolWindows.SolutionExplorer.GetItem(string.Format("{0}\\{1}", Path.GetFileNameWithoutExtension(Application.Solution.FullName), ProjectName.EvaluatedValue)).Select(vsUISelectionType.vsUISelectionTypeSelect); BuildProject.Save( ); Application.ExecuteCommand("Project.UnloadProject"); Application.ExecuteCommand("Project.ReloadProject"); Application.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate( ); Application.ToolWindows.SolutionExplorer.GetItem(string.Format("{0}\\{1}\\{2}", Path.GetFileNameWithoutExtension(Application.Solution.FullName), ProjectName.EvaluatedValue, oItem.EvaluatedInclude)).Select(vsUISelectionType.vsUISelectionTypeSelect); } else { GenerateProgress.GeneratorError(1, 1, "VSMinifier can't add minified file to project...", 0, 0); } } Output = 0; return(VSConstants.E_FAIL); }