public void InitializeProjects(List <IVsProject> upgradeProjects)
        {
            ProjectConverter.TryUpgrade(upgradeProjects);

            List <IVsProject> projects = DTEUtil.GetProjects();

            List <IVsProject> sliceProjects = new List <IVsProject>();

            foreach (IVsProject project in projects)
            {
                IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);

                if (projectType != IceBuilderProjectType.None)
                {
                    if (projectType == IceBuilderProjectType.CppProjectType)
                    {
                        VCUtil.SetupSliceFilter(DTEUtil.GetProject(project as IVsHierarchy));
                    }
                    if (AutoBuilding)
                    {
                        sliceProjects.Add(project);
                    }
                    else
                    {
                        FileTracker.Add(project, projectType);
                    }
                }
            }

            if (AutoBuilding)
            {
                QueueProjectsForBuilding(sliceProjects);
            }
        }
        private void PackageInstalled()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var projects = DTEUtil.GetProjects();

            foreach (IVsProject project in projects)
            {
                InitializeProject(project);
            }
        }
 public void InitializeProjects()
 {
     //
     // Postpone project initialization until the AddIn has been
     // removed.
     //
     if (!File.Exists(AddinPath))
     {
         OutputPane.Clear();
         InitializeProjects(DTEUtil.GetProjects(DTE.Solution));
     }
 }
Esempio n. 4
0
 public int OnAfterBackgroundSolutionLoadComplete()
 {
     try
     {
         Package.Instance.RunningDocumentTableEventHandler.BeginTrack();
         Package.Instance.InitializeProjects(DTEUtil.GetProjects());
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
     }
     return(0);
 }
Esempio n. 5
0
        private void PackageInstalled()
        {
            var projects = DTEUtil.GetProjects();

            foreach (IVsProject project in projects)
            {
                // Projects that are not being track has not been previous initialized
                // initialize will do nothing in zeroc.icebuilder.msbuild package is
                // not installed
                if (!FileTracker.Contains(ProjectUtil.GetProjectFullPath(project)))
                {
                    InitializeProject(project);
                }
            }
        }
Esempio n. 6
0
        private void PackageInstalled()
        {
            var projects = DTEUtil.GetProjects();

            foreach (IVsProject project in projects)
            {
                // Projects that are not being track has not been previous initialized
                // initialize will do nothing if zeroc.icebuilder.msbuild package is
                // not installed
                if (project.IsMSBuildIceBuilderInstalled())
                {
                    InitializeProject(project);
                }
            }
        }
        private void BuildEvents_OnBuildBegin(EnvDTE.vsBuildScope scope, EnvDTE.vsBuildAction action)
        {
            try
            {
                if (action == EnvDTE.vsBuildAction.vsBuildActionBuild ||
                    action == EnvDTE.vsBuildAction.vsBuildActionRebuildAll)
                {
                    //
                    // Ensure this runs once for parallel builds.
                    //
                    if (Building)
                    {
                        return;
                    }
                    Building = true;
                }

                List <IVsProject> projects = new List <IVsProject>();
                if (scope.Equals(EnvDTE.vsBuildScope.vsBuildScopeSolution))
                {
                    projects = DTEUtil.GetProjects();
                }
                else
                {
                    IVsProject selected = DTEUtil.GetSelectedProject();
                    if (selected != null)
                    {
                        projects.Add(selected);
                        DTEUtil.GetSubProjects(selected, ref projects);
                    }
                }

                foreach (IVsProject project in projects)
                {
                    IceBuilderProjectType type = DTEUtil.IsIceBuilderEnabled(project);
                    if (type != IceBuilderProjectType.None)
                    {
                        ProjectUtil.SetupGenerated(project, type);
                    }
                }
            }
            catch (Exception ex)
            {
                Package.UnexpectedExceptionWarning(ex);
                throw;
            }
        }
Esempio n. 8
0
 public void InitializeProjects(List <IVsProject> projects)
 {
     try
     {
         NuGet.OnNugetBatchEnd(null);
         ProjectConverter.TryUpgrade(projects);
         projects = DTEUtil.GetProjects();
         foreach (IVsProject project in projects)
         {
             InitializeProject(project);
         }
     }
     finally
     {
         NuGet.OnNugetBatchEnd(PackageInstalled);
     }
 }
        private void BuildEvents_OnBuildBegin(EnvDTE.vsBuildScope scope, EnvDTE.vsBuildAction action)
        {
            try
            {
                if (action == EnvDTE.vsBuildAction.vsBuildActionBuild ||
                    action == EnvDTE.vsBuildAction.vsBuildActionRebuildAll)
                {
                    //
                    // Ensure this runs once for parallel builds.
                    //
                    if (Building)
                    {
                        return;
                    }
                    Building = true;
                }

                List <EnvDTE.Project> projects = new List <EnvDTE.Project>();
                if (scope.Equals(EnvDTE.vsBuildScope.vsBuildScopeSolution))
                {
                    projects = DTEUtil.GetProjects(DTE2.Solution);
                }
                else
                {
                    EnvDTE.Project selected = DTEUtil.GetSelectedProject();
                    if (selected != null)
                    {
                        DTEUtil.GetProjects(selected, ref projects);
                    }
                }

                foreach (EnvDTE.Project project in projects)
                {
                    if (DTEUtil.IsIceBuilderEnabled(project))
                    {
                        FileTracker.Reap(project);
                        ProjectUtil.SetupGenerated(project);
                    }
                }
            }
            catch (Exception ex)
            {
                Package.UnexpectedExceptionWarning(ex);
                throw;
            }
        }
        private void BuildEvents_OnBuildBegin(EnvDTE.vsBuildScope scope, EnvDTE.vsBuildAction action)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                if (action == EnvDTE.vsBuildAction.vsBuildActionBuild ||
                    action == EnvDTE.vsBuildAction.vsBuildActionRebuildAll)
                {
                    //
                    // Ensure this runs once for parallel builds.
                    //
                    if (Building)
                    {
                        return;
                    }
                    Building = true;

                    List <IVsProject> projects = new List <IVsProject>();
                    if (scope.Equals(EnvDTE.vsBuildScope.vsBuildScopeSolution))
                    {
                        projects = DTEUtil.GetProjects();
                    }
                    else
                    {
                        IVsProject selected = DTEUtil.GetSelectedProject();
                        if (selected != null)
                        {
                            projects.Add(selected);
                            DTEUtil.GetSubProjects(selected, ref projects);
                        }
                    }

                    foreach (IVsProject project in projects)
                    {
                        if (project.IsMSBuildIceBuilderInstalled())
                        {
                            ProjectUtil.SetupGenerated(project);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                UnexpectedExceptionWarning(ex);
            }
        }
Esempio n. 11
0
 public int OnAfterBackgroundSolutionLoadComplete()
 {
     ThreadHelper.JoinableTaskFactory.Run(async() =>
     {
         await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
         try
         {
             Package.Instance.RunningDocumentTableEventHandler.BeginTrack();
             Package.Instance.InitializeProjects(DTEUtil.GetProjects());
         }
         catch (Exception ex)
         {
             Package.UnexpectedExceptionWarning(ex);
         }
     });
     return(0);
 }
 public void InitializeProjects(List <EnvDTE.Project> projects)
 {
     ProjectConverter.TryUpgrade(projects);
     projects = DTEUtil.GetProjects(DTE.Solution);
     foreach (EnvDTE.Project project in projects)
     {
         List <EnvDTE.Project> build = new List <EnvDTE.Project>();
         if (DTEUtil.IsIceBuilderEnabled(project))
         {
             if (DTEUtil.IsCppProject(project))
             {
                 VCUtil.SetupSliceFilter(project);
             }
             FileTracker.Add(project);
             build.Add(project);
         }
         QueueProjectsForBuilding(build);
     }
 }
        public void SetIceHome(String value)
        {
            if (String.IsNullOrEmpty(value))
            {
                //
                // Remove all registry settings.
                //
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceHomeValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceIntVersionValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionMMValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceCSharpAssembleyKey, "", "",
                                                  Microsoft.Win32.RegistryValueKind.String);

                if (DTE2.Solution != null)
                {
                    MSBuildUtils.SetIceHome(DTEUtil.GetProjects(DTE2.Solution), "", "", "", "");
                }
                return;
            }
            else
            {
                Version v = null;

                try
                {
                    String compiler = GetSliceCompilerVersion(value);
                    if (String.IsNullOrEmpty(compiler))
                    {
                        string err = "Unable to find a valid Ice installation in `" + value + "'";

                        MessageBox.Show(err,
                                        "Ice Builder",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button1,
                                        (MessageBoxOptions)0);
                        return;
                    }
                    else
                    {
                        v = Version.Parse(compiler);
                    }
                }
                catch (System.Exception ex)
                {
                    string err = "Failed to run Slice compiler using Ice installation from `" + value + "'"
                                 + "\n" + ex.ToString();

                    MessageBox.Show(err, "Ice Builder",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                    (MessageBoxOptions)0);
                    return;
                }
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceHomeValue, value,
                                                  Microsoft.Win32.RegistryValueKind.String);

                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionValue, v.ToString(),
                                                  Microsoft.Win32.RegistryValueKind.String);

                String iceIntVersion = String.Format("{0}{1:00}{2:00}", v.Major, v.Minor, v.Build);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceIntVersionValue,
                                                  iceIntVersion,
                                                  Microsoft.Win32.RegistryValueKind.String);

                String iceVersionMM = String.Format("{0}.{1}", v.Major, v.Minor);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionMMValue, iceVersionMM,
                                                  Microsoft.Win32.RegistryValueKind.String);

                if (DTE2.Solution != null)
                {
                    MSBuildUtils.SetIceHome(DTEUtil.GetProjects(DTE2.Solution), value, v.ToString(), iceIntVersion, iceVersionMM);
                }

                Microsoft.Win32.Registry.SetValue(IceCSharpAssembleyKey, "", GetAssembliesDir(value),
                                                  Microsoft.Win32.RegistryValueKind.String);
            }
        }
Esempio n. 14
0
 public void InitializeProjects()
 {
     OutputPane.Clear();
     InitializeProjects(DTEUtil.GetProjects(DTE.Solution));
 }
        protected override async Task InitializeAsync(CancellationToken cancel,
                                                      IProgress <Microsoft.VisualStudio.Shell.ServiceProgressData> progress)
        {
            Instance = this;
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            AutoBuilding = GetAutoBuilding();

            object value = null;

            {
                Shell = await GetServiceAsync(typeof(IVsShell)) as IVsShell;

                if (Shell == null)
                {
                    throw new PackageInitializationException("Error initializing Shell");
                }
                Shell.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out value);
                CommandLineMode = (bool)value;
            }

            if (!CommandLineMode)
            {
                InstallDirectory   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                ResourcesDirectory = Path.Combine(InstallDirectory, "Resources");

                DTE2 = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;

                if (DTE2 == null)
                {
                    throw new PackageInitializationException("Error initializing DTE2");
                }

                DTEEvents = DTE.Events.DTEEvents;

                IVsSolution = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution;

                if (IVsSolution == null)
                {
                    throw new PackageInitializationException("Error initializing IVsSolution");
                }

                IVsSolution4 = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution4;

                if (IVsSolution4 == null)
                {
                    throw new PackageInitializationException("Error initializing IVsSolution4");
                }

                UIShell = await GetServiceAsync(typeof(SVsUIShell)) as IVsUIShell;

                if (UIShell == null)
                {
                    throw new PackageInitializationException("Error initializing UIShell");
                }

                MonitorSelection = await GetServiceAsync(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

                if (MonitorSelection == null)
                {
                    throw new PackageInitializationException("Error initializing MonitorSelection");
                }

                //
                // Update the InstallDir this was previously used in project imports, but is still usefull if you
                // need to detect the extension install dir.
                //
                Registry.SetValue(IceBuilderKey, string.Format("InstallDir.{0}", DTE.Version), InstallDirectory,
                                  RegistryValueKind.String);

                Assembly assembly = null;
                if (DTE.Version.StartsWith("14.0"))
                {
                    assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2015.dll"));
                }
                else if (DTE.Version.StartsWith("15.0"))
                {
                    assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2017.dll"));
                }
                else
                {
                    assembly = Assembly.LoadFrom(Path.Combine(ResourcesDirectory, "IceBuilder.VS2019.dll"));
                }
                var factory = assembly.GetType("IceBuilder.ProjectHelperFactoryI").GetConstructor(new Type[] { }).Invoke(
                    new object[] { }) as IVsProjectHelperFactory;

                VCUtil        = factory.VCUtil;
                NuGet         = factory.NuGet;
                ProjectHelper = factory.ProjectHelper;

                ProjectFactoryHelperInstance.Init(VCUtil, NuGet, ProjectHelper);

                NuGet.OnNugetBatchEnd(PackageInstalled);

                RunningDocumentTableEventHandler = new RunningDocumentTableEventHandler(
                    await GetServiceAsync(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable);

                Builder = new Builder(await GetServiceAsync(typeof(SVsBuildManagerAccessor)) as IVsBuildManagerAccessor2);

                //
                // Subscribe to solution events.
                //
                SolutionEventHandler = new SolutionEventHandler();
                SolutionEventHandler.BeginTrack();

                DocumentEventHandler = new DocumentEventHandler(
                    await GetServiceAsync(typeof(SVsTrackProjectDocuments)) as IVsTrackProjectDocuments2);
                DocumentEventHandler.BeginTrack();

                BuildEvents = DTE2.Events.BuildEvents;
                BuildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
                BuildEvents.OnBuildDone  += BuildEvents_OnBuildDone;
            }

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            RegisterProjectFactory(new ProjectFactory());
            RegisterProjectFactory(new ProjectFactoryOld());

            value = null;
            IVsSolution.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out value);
            if ((bool)value)
            {
                RunningDocumentTableEventHandler.BeginTrack();
                InitializeProjects(DTEUtil.GetProjects());
            }
        }
        public void SetIceHome(String value)
        {
            if (String.IsNullOrEmpty(value))
            {
                //
                // Remove all registry settings.
                //
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceHomeValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceIntVersionValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionMMValue, "",
                                                  Microsoft.Win32.RegistryValueKind.String);
                Microsoft.Win32.Registry.SetValue(IceCSharpAssembleyKey, "", "",
                                                  Microsoft.Win32.RegistryValueKind.String);


                MSBuildUtils.SetIceHome(DTEUtil.GetProjects(), "", "", "", "");
                return;
            }
            else
            {
                String props = File.Exists(Path.Combine(value, "config", "Ice.props")) ? Path.Combine(value, "config", "Ice.props") :
                               File.Exists(Path.Combine(value, "cpp", "config", "Ice.props")) ? Path.Combine(value, "cpp", "config", "Ice.props") :
                               File.Exists(Path.Combine(value, "build", "native", "Ice.props")) ? Path.Combine(value, "build", "native", "Ice.props") : null;

                if (!String.IsNullOrEmpty(props))
                {
                    Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation.Project(
                        props,
                        new Dictionary <String, String>()
                    {
                        { "ICE_HOME", value }
                    },
                        null);
                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceHomeValue, value,
                                                      Microsoft.Win32.RegistryValueKind.String);

                    String version = p.GetPropertyValue(IceVersionValue);
                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionValue, version,
                                                      Microsoft.Win32.RegistryValueKind.String);

                    String intVersion = p.GetPropertyValue(IceIntVersionValue);
                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceIntVersionValue,
                                                      intVersion,
                                                      Microsoft.Win32.RegistryValueKind.String);

                    String mmVersion = p.GetPropertyValue(IceVersionMMValue);
                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionMMValue, mmVersion,
                                                      Microsoft.Win32.RegistryValueKind.String);

                    MSBuildUtils.SetIceHome(DTEUtil.GetProjects(), value, version, intVersion, mmVersion);

                    Microsoft.Win32.Registry.SetValue(IceCSharpAssembleyKey, "", GetAssembliesDir(value),
                                                      Microsoft.Win32.RegistryValueKind.String);

                    ICollection <Microsoft.Build.Evaluation.Project> projects =
                        Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.GetLoadedProjects(props);
                    if (projects.Count > 0)
                    {
                        Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.UnloadProject(p);
                    }
                }
                else
                {
                    Version v = null;
                    try
                    {
                        String compiler = GetSliceCompilerVersion(value);
                        if (String.IsNullOrEmpty(compiler))
                        {
                            string err = "Unable to find a valid Ice installation in `" + value + "'";

                            MessageBox.Show(err,
                                            "Ice Builder",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error,
                                            MessageBoxDefaultButton.Button1,
                                            (MessageBoxOptions)0);
                            return;
                        }
                        else
                        {
                            v = Version.Parse(compiler);
                        }
                    }
                    catch (System.Exception ex)
                    {
                        string err = "Failed to run Slice compiler using Ice installation from `" + value + "'"
                                     + "\n" + ex.ToString();

                        MessageBox.Show(err, "Ice Builder",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                                        (MessageBoxOptions)0);
                        return;
                    }
                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceHomeValue, value,
                                                      Microsoft.Win32.RegistryValueKind.String);

                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionValue, v.ToString(),
                                                      Microsoft.Win32.RegistryValueKind.String);

                    String iceIntVersion = String.Format("{0}{1:00}{2:00}", v.Major, v.Minor, v.Build);
                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceIntVersionValue,
                                                      iceIntVersion,
                                                      Microsoft.Win32.RegistryValueKind.String);

                    String iceVersionMM = String.Format("{0}.{1}", v.Major, v.Minor);
                    Microsoft.Win32.Registry.SetValue(IceHomeKey, IceVersionMMValue, iceVersionMM,
                                                      Microsoft.Win32.RegistryValueKind.String);

                    MSBuildUtils.SetIceHome(DTEUtil.GetProjects(), value, v.ToString(), iceIntVersion, iceVersionMM);

                    Microsoft.Win32.Registry.SetValue(IceCSharpAssembleyKey, "", GetAssembliesDir(value),
                                                      Microsoft.Win32.RegistryValueKind.String);
                }
            }
        }