private void OnDocumentSaved(EnvDTE.Document dteDocument)
		{
			var documentIds = this.workspace.CurrentSolution.GetDocumentIdsWithFilePath(
				dteDocument.FullName);

			if(documentIds != null && documentIds.Length == 1)
			{
				var documentId = documentIds[0];
				var document = this.workspace.CurrentSolution.GetDocument(documentId);

				if (Path.GetExtension(document.FilePath) == ".cs")
				{
					SyntaxNode root = null;

					if (document.TryGetSyntaxRoot(out root))
					{
						var newRoot = root.RemoveComments();

						if (newRoot != root)
						{
							var newSolution = document.Project.Solution
								.WithDocumentSyntaxRoot(document.Id, newRoot);
							this.workspace.TryApplyChanges(newSolution);
							dteDocument.Save();
						}
					}
				}
			}
		}
Example #2
0
 public static async void DoWorkInWriterLock(EnvDTE.Project project, IVsHierarchy hierarchy, Action<MsBuildProject> action)
 {
     await DoWorkInWriterLock((IVsProject)hierarchy, action);
     var fileSystem = new PhysicalFileSystem(@"c:\");
     fileSystem.MakeFileWritable(project.FullName);
     project.Save();
 }
        public void ProjectFinishedGenerating(EnvDTE.Project project)
        {
            var viewModel = new CreateProjectViewModel(BuildProjectionManager);
            var view = new CreateProjectWizardView(viewModel);
            if (!view.ShowDialog().GetValueOrDefault(false)) return;

            var projectNode = (ProjectionsProjectNode) project.Object;

            if (viewModel.State.ProjectionsToImport.Any())
            {
                var projectionsManager = BuildProjectionManager(viewModel.State.EventStoreConnection);
                AsyncHelpers.RunSync(() => ImportProjectionsAsync(projectNode, projectionsManager, viewModel.State.ProjectionsToImport));
            }

            project.Save();
            projectNode.CurrentConfig.SetProperty(Constants.EventStore.ConnectionString, viewModel.State.EventStoreConnection);
            project.Save();
        }
Example #4
0
        internal void OpenProject(VisualStudioApp app, string slnName, out PythonProjectNode projectNode, out EnvDTE.Project dteProject) {
            PythonVersion.AssertInstalled();

            dteProject = app.OpenProject("TestData\\Targets\\" + slnName);
            projectNode = dteProject.GetPythonProject();
            var fact = projectNode.InterpreterFactories.Where(x => x.Configuration.Id == PythonVersion.Id).FirstOrDefault();
            Assert.IsNotNull(fact, "Project does not contain expected interpreter");
            projectNode.ActiveInterpreter = fact;
            dteProject.Save();
        }
Example #5
0
        /// <summary>
        /// Toggles the kind of a project. If the project is a QMake generated project (qmake -tp vc)
        /// it is transformed to an Add-in Qt project and vice versa.
        /// </summary>
        /// <param name="project">Project</param>
        /// <returns></returns>
        public static void ToggleProjectKind(EnvDTE.Project project)
        {
            string qtDir = null;
            VCProject vcPro = (VCProject)project.Object;
            if (!IsQMakeProject(project))
                return;

            if (IsQt5Project(project))
            {
                QtProject qtPro = QtProject.Create(project);
                QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetProjectPlatformName(project));

                qtDir = vm.GetInstallPath(project);

                foreach (string global in (string[])project.Globals.VariableNames)
                {
                    if (global.StartsWith("Qt5Version"))
                    {
                        project.Globals.set_VariablePersists(global, false);
                    }
                }

                foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");
                    VCLibrarianTool librarian = (VCLibrarianTool)((IVCCollection)config.Tools).Item("VCLibrarianTool");
                    if (compiler != null)
                    {
                        string additionalIncludes = compiler.GetAdditionalIncludeDirectories();
                        additionalIncludes = ReplaceCaseInsensitive(additionalIncludes, "$(QTDIR)", qtDir);
                        compiler.SetAdditionalIncludeDirectories(additionalIncludes);
                    }
                    if (linker != null)
                    {
                        linker.AdditionalLibraryDirectories = ReplaceCaseInsensitive(linker.AdditionalLibraryDirectories, "$(QTDIR)", qtDir);
                        linker.AdditionalDependencies = AddFullPathToAdditionalDependencies(qtDir, linker.AdditionalDependencies);
                    }
                    else
                    {
                        librarian.AdditionalLibraryDirectories = ReplaceCaseInsensitive(librarian.AdditionalLibraryDirectories, "$(QTDIR)", qtDir);
                        librarian.AdditionalDependencies = AddFullPathToAdditionalDependencies(qtDir, librarian.AdditionalDependencies);
                    }
                }

                ReplaceInCustomBuildTools(project, "$(QTDIR)", qtDir);
            }
            else if (IsQMakeProject(project))
            {
                qtDir = GetQtDirFromQMakeProject(project);

                QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetProjectPlatformName(project));

                string qtVersion = vm.GetQtVersionFromInstallDir(qtDir);
                if (qtVersion == null)
                    qtVersion = "$(DefaultQtVersion)";
                if (qtDir == null)
                    qtDir = vm.GetInstallPath(qtVersion);
                VersionInformation vi = vm.GetVersionInfo(qtVersion);
                string platformName = vi.GetVSPlatformName();
                vm.SaveProjectQtVersion(project, qtVersion, platformName);
                QtProject qtPro = QtProject.Create(project);
                if (!qtPro.SelectSolutionPlatform(platformName) || !qtPro.HasPlatform(platformName))
                {
                    bool newProject = false;
                    qtPro.CreatePlatform("Win32", platformName, null, vi, ref newProject);
                    if (!qtPro.SelectSolutionPlatform(platformName))
                    {
                        Messages.PaneMessage(project.DTE, "Can't select the platform " + platformName + ".");
                    }
                }

                string activeConfig = project.ConfigurationManager.ActiveConfiguration.ConfigurationName;
                VCConfiguration activeVCConfig = (VCConfiguration)((IVCCollection)qtPro.VCProject.Configurations).Item(activeConfig);
                if (activeVCConfig.ConfigurationType == ConfigurationTypes.typeDynamicLibrary)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(activeVCConfig);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)activeVCConfig.Tools).Item("VCLinkerTool");
                    string ppdefs = compiler.GetPreprocessorDefinitions();
                    if (ppdefs != null
                        && ppdefs.IndexOf("QT_PLUGIN") > -1
                        && ppdefs.IndexOf("QDESIGNER_EXPORT_WIDGETS") > -1
                        && ppdefs.IndexOf("QtDesigner") > -1
                        && linker.AdditionalDependencies != null
                        && linker.AdditionalDependencies.IndexOf("QtDesigner") > -1)
                    {
                        qtPro.MarkAsDesignerPluginProject();
                    }
                }

                HelperFunctions.CleanupQMakeDependencies(project);

                foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                    if (compiler != null)
                    {
                        List<string> additionalIncludes = compiler.AdditionalIncludeDirectories;
                        if (additionalIncludes != null)
                        {
                            ReplaceDirectory(ref additionalIncludes, qtDir, "$(QTDIR)", project);
                            compiler.AdditionalIncludeDirectories = additionalIncludes;
                        }
                    }
                    if (linker != null)
                    {
                        LinkerToolWrapper linkerToolWrapper = new LinkerToolWrapper(linker);
                        List<string> additionalLibraries = linkerToolWrapper.AdditionalLibraryDirectories;
                        if (additionalLibraries != null)
                        {
                            ReplaceDirectory(ref additionalLibraries, qtDir, "$(QTDIR)", project);
                            linkerToolWrapper.AdditionalLibraryDirectories = additionalLibraries;
                        }
                    }
                }

                ReplaceInCustomBuildTools(project, qtDir, "$(QTDIR)");
                qtPro.TranslateFilterNames();
            }
            else
            {
                QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetProjectPlatformName(project));

                string qtVersion = vm.GetQtVersionFromInstallDir(qtDir);
                if (qtVersion == null)
                    qtVersion = "$(DefaultQtVersion)";
                if (qtDir == null)
                    qtDir = vm.GetInstallPath(qtVersion);

                VersionInformation vi = vm.GetVersionInfo(qtVersion);
                string platformName = vi.GetVSPlatformName();

                vm.SaveProjectQtVersion(project, qtVersion, platformName);
                QtProject qtPro = QtProject.Create(project);
                qtPro.MarkAsQtProject("v1.0");

                if (!qtPro.SelectSolutionPlatform(platformName) || !qtPro.HasPlatform(platformName))
                {
                    bool newProject = false;
                    qtPro.CreatePlatform("Win32", platformName, null, vi, ref newProject);
                    if (!qtPro.SelectSolutionPlatform(platformName))
                    {
                        Messages.PaneMessage(project.DTE, "Can't select the platform " + platformName + ".");
                    }
                }

                foreach (VCConfiguration config in (IVCCollection)vcPro.Configurations)
                {
                    CompilerToolWrapper compiler = CompilerToolWrapper.Create(config);
                    VCLinkerTool linker = (VCLinkerTool)((IVCCollection)config.Tools).Item("VCLinkerTool");

                    if (compiler != null)
                    {
                        List<string> additionalIncludes = compiler.AdditionalIncludeDirectories;
                        if (additionalIncludes != null)
                        {
                            additionalIncludes.Add("$(QTDIR)\\include");
                            compiler.AdditionalIncludeDirectories = additionalIncludes;
                        }
                    }
                    if (linker != null)
                    {
                        LinkerToolWrapper linkerToolWrapper = new LinkerToolWrapper(linker);
                        List<string> additionalLibraries = linkerToolWrapper.AdditionalLibraryDirectories;
                        if (additionalLibraries != null)
                        {
                            additionalLibraries.Add("$(QTDIR)\\lib");
                            linkerToolWrapper.AdditionalLibraryDirectories = additionalLibraries;
                        }
                        if (config.ConfigurationType == ConfigurationTypes.typeApplication)
                        {
                            List<string> additionalDependencies = linkerToolWrapper.AdditionalDependencies;
                            if (additionalDependencies != null)
                            {
                                if (config.ConfigurationName.IndexOf("Debug") != -1)
                                {
                                    additionalDependencies.Add("qtmaind.lib");
                                }
                                else
                                {
                                    additionalDependencies.Add("qtmain.lib");
                                }
                                linkerToolWrapper.AdditionalDependencies = additionalDependencies;
                            }
                        }
                    }
                }

                qtPro.TranslateFilterNames();
            }
            project.Save(project.FullName);
        }
Example #6
0
 public static async void DoWorkInWriterLock(EnvDTE.Project project, IVsHierarchy hierarchy, Action<MsBuildProject> action)
 {
     await DoWorkInWriterLock((IVsProject)hierarchy, action);
     project.Save();
 }
 public void AddIceBuilderToProject(EnvDTE.Project p)
 {
     Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName);
     if (MSBuildUtils.AddIceBuilderToProject(project))
     {
         if (DTEUtil.IsCppProject(p))
         {
             VCUtil.SetupSliceFilter(p);
         }
         else
         {
             String includeDirectories = ProjectUtil.GetProperty(p, PropertyNames.IncludeDirectories);
             if (String.IsNullOrEmpty(includeDirectories))
             {
                 ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories, @"$(IceHome)\slice");
             }
             else if(includeDirectories.IndexOf(@"$(IceHome)\slice") == -1)
             {
                 ProjectUtil.SetProperty(p, PropertyNames.IncludeDirectories,
                     String.Format(@"$(IceHome)\slice;{0}", includeDirectories));
             }
             ProjectUtil.AddAssemblyReference(p, "Ice");
         }
         p.Save();
         IVsHierarchy hier = DTEUtil.GetIVsHierarchy(p);
         Guid projectGUID = Guid.Empty;
         IVsSolution.GetGuidOfProject(hier, out projectGUID);
         IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0);
         project.Save();
         IVsSolution4.ReloadProject(ref projectGUID);
     }
 }
        private void RemoveIceBuilderFromProject(EnvDTE.Project p)
        {
            Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName);
            MSBuildUtils.RemoveIceBuilderFromProject(project);
            foreach (EnvDTE.Project p1 in _buildProjects)
            {
                if(p.FullName.Equals(p.FullName))
                {
                    _buildProjects.Remove(p1);
                    break;
                }
            }

            ProjectUtil.DeleteItems(p,
                ProjectUtil.GetGeneratedFiles(p).Aggregate(
                    new List<String>(),
                    (items, kv) =>
                        {
                            items.AddRange(kv.Value);
                            return items;
                        }));

            Directory.GetFiles(GetAssembliesDir(GetIceHome()), "*.dll")
                .ToList()
                .ForEach(item =>
                    {
                        String name = Path.GetFileNameWithoutExtension(item);
                        if(ProjectUtil.HasAssemblyReference(p, name))
                        {
                            ProjectUtil.RemoveAssemblyReference(p, name);
                        }
                    });
            p.Save();

            Guid projectGUID = Guid.Empty;
            IVsHierarchy hier = DTEUtil.GetIVsHierarchy(p);
            IVsSolution.GetGuidOfProject(hier, out projectGUID);
            IVsSolution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, hier, 0);
            project.Save();
            IVsSolution4.ReloadProject(ref projectGUID);
        }
        public bool Build(EnvDTE.Project p, BuildCallback buildCallback, BuildLogger buildLogger)
        {
            p.Save();
            MSBuildProject project = MSBuildUtils.LoadedProject(p.FullName, false);

            //
            // We need to set this before we acquire the build resources otherwise Msbuild
            // will not see the changes.
            //
            bool onlyLogCriticalEvents = project.ProjectCollection.OnlyLogCriticalEvents;
            project.ProjectCollection.Loggers.Add(buildLogger);
            project.ProjectCollection.OnlyLogCriticalEvents = false;

            uint cookie;
            int err = BuildManagerAccessor.AcquireBuildResources(VSBUILDMANAGERRESOURCE.VSBUILDMANAGERRESOURCE_DESIGNTIME |
                                                                 VSBUILDMANAGERRESOURCE.VSBUILDMANAGERRESOURCE_UITHREAD, out cookie);

            if (err != VSConstants.E_PENDING && err != VSConstants.S_OK)
            {
                ErrorHandler.ThrowOnFailure(err);
            }

            if (err == VSConstants.E_PENDING)
            {
                project.ProjectCollection.Loggers.Remove(buildLogger);
                project.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents;

                Dispatcher = Dispatcher.CurrentDispatcher;
                BuildAvailableEvent = new System.Threading.ManualResetEvent(false);
                BuildAvailableEvent.SafeWaitHandle = new SafeWaitHandle(BuildManagerAccessor.DesignTimeBuildAvailable, false);

                Thread t = new Thread(() =>
                    {
                        BuildAvailableEvent.WaitOne();
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            Package.Instance.BuildNextProject();
                        }));
                    });
                t.Start();
                return false;
            }
            else
            {
                Package.Instance.FileTracker.Reap(p);
                ProjectUtil.SetupGenerated(p);
                
                try
                {
                    BuildRequestData buildRequest = new BuildRequestData(
                            BuildManager.DefaultBuildManager.GetProjectInstanceForBuild(project),
                            new String[] { "IceBuilder_Compile" },
                            project.ProjectCollection.HostServices,
                            BuildRequestDataFlags.IgnoreExistingProjectState |
                            BuildRequestDataFlags.ReplaceExistingProjectInstance);

                    BuildSubmission submission = BuildManager.DefaultBuildManager.PendBuildRequest(buildRequest);
                    ErrorHandler.ThrowOnFailure(BuildManagerAccessor.RegisterLogger(submission.SubmissionId, buildLogger));
                    buildCallback.BeginBuild();
                    submission.ExecuteAsync((s) =>
                        {
                            Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() =>
                            {
                                project.ProjectCollection.Loggers.Remove(buildLogger);
                                project.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents;
                                BuildManagerAccessor.ReleaseBuildResources(cookie);
                                BuildManagerAccessor.UnregisterLoggers(submission.SubmissionId);
                                buildCallback.EndBuild(submission.BuildResult.OverallResult == BuildResultCode.Success);
                            }));
                        }, null);
                    
                    return true;
                }
                catch (Exception)
                {
                    project.ProjectCollection.Loggers.Remove(buildLogger);
                    project.ProjectCollection.OnlyLogCriticalEvents = onlyLogCriticalEvents;
                    BuildManagerAccessor.ReleaseBuildResources(cookie);
                    throw;
                }
            }
        }