예제 #1
0
        /// <summary>
        /// Provide UI to add a JAR reference.
        /// </summary>
        private void AddJarReference()
        {
            // Get the current project
            var project = (IVsHierarchy)GetCurrentProject();

            using (var dialog = new AddJarReferenceDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var jarPath    = dialog.JarPath;
                    var libName    = dialog.LibraryName;
                    var importCode = dialog.ImportCode;

                    var item = BuildProject.AddItem("JarReference", jarPath).Single();
                    if (!string.IsNullOrEmpty(libName))
                    {
                        item.SetMetadataValue("LibraryName", libName);
                    }
                    if (importCode)
                    {
                        item.SetMetadataValue("ImportCode", "yes");
                    }

                    // Save project
                    BuildProject.Save();

                    // Unload the project - also saves the modifications
                    ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, project, 0));

                    // Reload project
                    dte.ExecuteCommand("Project.ReloadProject", "");
                }
            }
        }
        protected override void LoadNonBuildInformation()
        {
            string filepath = this.FileName + ".user";

            if (File.Exists(filepath))
            {
                Microsoft.Build.Evaluation.Project pb = new Microsoft.Build.Evaluation.Project();
                BuildProject.DisableMarkDirty = true;
                var projuser = pb.ProjectCollection.LoadProject(filepath);
                foreach (string key in _userproperties)
                {
                    try
                    {
                        foreach (var group in projuser.Xml.PropertyGroups)
                        {
                            bool gotit = false;
                            foreach (var p in group.Properties)
                            {
                                if (p.Name == key)
                                {
                                    BuildProject.SetGlobalProperty(key, p.Value);
                                    OnUserPropertyLoad(key, p.Value);
                                    gotit = true;
                                    break;
                                }
                            }
                            if (gotit)
                            {
                                break;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //
                    }
                }
                pb.ProjectCollection.UnloadProject(projuser);
                BuildProject.DisableMarkDirty = false;
                BuildProject.Save();
            }
            base.LoadNonBuildInformation();
        }
예제 #3
0
        private void SaveProject(object sender, RoutedEventArgs e)
        {
            //Save the project if needed
            if (m_Project.Dirty)
            {
                if (m_Project.Filename.Length == 0)
                {
                    System.Windows.Forms.SaveFileDialog fileDialog = new System.Windows.Forms.SaveFileDialog();
                    fileDialog.Filter = "MS Build Project Files|*.*proj";

                    System.Windows.Forms.DialogResult dr = fileDialog.ShowDialog();

                    if (dr == System.Windows.Forms.DialogResult.OK)
                    {
                        m_Project.Filename = fileDialog.FileName;
                    }
                }

                m_Project.Save();
            }
        }
예제 #4
0
        /// <summary>
        /// Implements deferred save support.  Enabled by unchecking Tools->Options->Solutions and Projects->Save New Projects Created.
        ///
        /// In this mode we save the project when the user selects Save All.  We need to move all the files in the project
        /// over to the new location.
        /// </summary>
        public virtual int SaveProjectToLocation(string pszProjectFilename)
        {
            string oldName  = Url;
            string basePath = Path.GetDirectoryName(this.FileName) + Path.DirectorySeparatorChar;
            string newName  = Path.GetDirectoryName(pszProjectFilename);

            // we don't use RenameProjectFile because it sends the OnAfterRenameProject event too soon
            // and causes VS to think the solution has changed on disk.  We need to send it after all
            // updates are complete.

            // save the new project to to disk
            SaveMSBuildProjectFileAs(pszProjectFilename);

            // remove all the children, saving any dirty files, and collecting the list of open files
            MoveFilesForDeferredSave(this, basePath, newName);

            _projectDir = newName;

            // save the project again w/ updated file info
            BuildProject.Save();

            SetProjectFileDirty(false);

            // update VS that we've changed the project
            this.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_Caption, 0);

            IVsUIShell  shell      = this.Site.GetService(typeof(SVsUIShell)) as IVsUIShell;
            IVsSolution vsSolution = (IVsSolution)this.GetService(typeof(SVsSolution));

            // Update solution
            ErrorHandler.ThrowOnFailure(vsSolution.OnAfterRenameProject((IVsProject)this, oldName, pszProjectFilename, 0));

            ErrorHandler.ThrowOnFailure(shell.RefreshPropertyBrowser(0));

            return(VSConstants.S_OK);
        }
예제 #5
0
        /// <summary>
        /// Provide UI to import a res folder.
        /// </summary>
        private void ImportResFolder()
        {
            // Get the current project
            var project = (IVsHierarchy)GetCurrentProject();

            using (var dialog = new FolderBrowserDialog())
            {
                dialog.Description = "Select existing res folder to import.";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        var resFolder     = dialog.SelectedPath;
                        var projectFolder = ProjectFolder;

                        // Do the import
                        ResFolderImporter.ImportResFolder(resFolder, projectFolder, AddFileToProject);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("Failed to import res folder because: {0}", ex.Message), VSPackage._110, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        // Save project
                        BuildProject.Save();

                        // Unload the project - also saves the modifications
                        ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, project, 0));

                        // Reload project
                        dte.ExecuteCommand("Project.ReloadProject", "");
                    }
                }
            }
        }
예제 #6
0
        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);
        }