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 static bool Upgrade(IVsProject project)
        {
            OldConfiguration oldConfiguration = new OldConfiguration();

            Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(project), DTEUtil.IsCppProject(project), true);

            if (oldConfiguration.Load(msbuildProject, true))
            {
                if (DTEUtil.IsCppProject(project))
                {
                    return(UpgadeCppConfiguration(msbuildProject, oldConfiguration));
                }
                else if (DTEUtil.IsCSharpProject(project))
                {
                    return(UpgradeCSharpConfiguration(DTEUtil.GetProject(project as IVsHierarchy), msbuildProject, oldConfiguration));
                }
            }
            return(false);
        }
Example #3
0
        public static bool Upgrade(EnvDTE.Project project)
        {
            OldConfiguration oldConfiguration = new OldConfiguration();

            Microsoft.Build.Evaluation.Project msbuildProject = MSBuildUtils.LoadedProject(project.FullName);

            if (oldConfiguration.Load(msbuildProject, true))
            {
                if (DTEUtil.IsCppProject(project))
                {
                    return(UpgadeCppConfiguration(msbuildProject, oldConfiguration));
                }
                else if (DTEUtil.IsCSharpProject(project))
                {
                    return(UpgradeCSharpConfiguration(project, msbuildProject, oldConfiguration));
                }
            }
            return(false);
        }
 //
 // Check if IceBuilder 4.x is enabled
 //
 public static IceBuilderProjectType IsIceBuilderEnabled(IVsProject project)
 {
     if (project != null)
     {
         IceBuilderProjectType type = project.IsCppProject() ? IceBuilderProjectType.CppProjectType :
                                      project.IsCSharpProject() ? IceBuilderProjectType.CsharpProjectType : IceBuilderProjectType.None;
         if (type != IceBuilderProjectType.None)
         {
             return(project.WithProject((MSProject msproject) =>
             {
                 if (MSBuildUtils.IsIceBuilderEnabled(msproject))
                 {
                     return type;
                 }
                 return IceBuilderProjectType.None;
             }));
         }
     }
     return(IceBuilderProjectType.None);
 }
        //
        // Set Ice Home and force projects to re evaluate changes in the imported project
        //
        public static void SetIceHome(List <EnvDTE.Project> projects, String iceHome, String iceVersion, String iceIntVersion, String iceVersionMM)
        {
            foreach (EnvDTE.Project p in projects)
            {
                Microsoft.Build.Evaluation.Project project = MSBuildUtils.LoadedProject(p.FullName);
                ResolvedImport import = project.Imports.FirstOrDefault(i => i.ImportedProject.FullPath.EndsWith("IceBuilder.Common.props"));

                if (import.ImportedProject != null)
                {
                    ProjectPropertyGroupElement group = import.ImportedProject.PropertyGroups.FirstOrDefault(g => g.Label.Equals("IceHome"));
                    if (group != null)
                    {
                        group.SetProperty(Package.IceHomeValue, iceHome);
                        group.SetProperty(Package.IceVersionValue, iceVersion);
                        group.SetProperty(Package.IceIntVersionValue, iceIntVersion);
                        group.SetProperty(Package.IceVersionMMValue, iceVersionMM);
                        project.ReevaluateIfNecessary();
                    }
                }
            }
        }
 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();
         try
         {
             ProjectCollection.GlobalProjectCollection.UnloadProject(project);
         }
         catch (System.Exception)
         {
             //expected if the project is not in the global project collection
         }
         IVsSolution4.ReloadProject(ref projectGUID);
     }
 }
        private string GetSliceCompilerPath(Microsoft.Build.Evaluation.Project project, string iceHome)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            string compiler = MSBuildUtils.IsCSharpProject(project) ? "slice2cs.exe" : "slice2cpp.exe";

            if (!string.IsNullOrEmpty(iceHome))
            {
                if (File.Exists(Path.Combine(iceHome, "cpp", "bin", compiler)))
                {
                    return(Path.Combine(iceHome, "cpp", "bin", compiler));
                }

                if (File.Exists(Path.Combine(iceHome, "bin", compiler)))
                {
                    return(Path.Combine(iceHome, "bin", compiler));
                }
            }

            string message = "'" + compiler + "' not found";

            if (!string.IsNullOrEmpty(iceHome))
            {
                message += " in '" + iceHome + "'. You may need to update Ice Home in 'Tools > Options > Ice'";
            }
            else
            {
                message += ". You may need to set Ice Home in 'Tools > Options > Ice'";
            }
            OutputPane.OutputTaskItemString(
                message,
                EnvDTE.vsTaskPriority.vsTaskPriorityHigh,
                "BuildCompile",
                EnvDTE.vsTaskIcon.vsTaskIconCompile,
                compiler,
                0,
                message);
            return(null);
        }
Example #8
0
        public static void TryUpgrade(List <EnvDTE.Project> projects)
        {
            String solutionDir = Path.GetDirectoryName(Package.Instance.DTE2.Solution.FullName);
            Dictionary <String, EnvDTE.Project> upgradeProjects = new Dictionary <String, EnvDTE.Project>();

            foreach (EnvDTE.Project project in projects)
            {
                if (new OldConfiguration().Load(MSBuildUtils.LoadedProject(project.FullName), false))
                {
                    upgradeProjects.Add(
                        FileUtil.RelativePath(solutionDir, project.FullName),
                        project);
                }
            }

            if (upgradeProjects.Count > 0)
            {
                UpgradeDialog dialog = new UpgradeDialog();
                dialog.StartPosition = FormStartPosition.CenterParent;
                dialog.Projects      = upgradeProjects;
                dialog.ShowDialog();
            }
        }
Example #9
0
        public void InitializeProject(IVsProject project)
        {
            IceBuilderProjectType projectType = DTEUtil.IsIceBuilderNuGetInstalled(project);

            if (projectType != IceBuilderProjectType.None)
            {
                var dteproject = project.GetDTEProject();
                if (projectType == IceBuilderProjectType.CppProjectType)
                {
                    VCUtil.SetupSliceFilter(dteproject);
                }
                else
                {
                    if (project is IVsAggregatableProject)
                    {
                        if (MSBuildUtils.AddProjectFlavorIfNotExists(project.GetMSBuildProject(true), IceBuilderNewFlavor))
                        {
                            dteproject.Save();
                        }
                    }
                }
                FileTracker.Add(project, projectType);
            }
        }
        public static void Upgrade(Dictionary <string, IVsProject> projects, UpgradeProgressCallback progressCallback)
        {
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
            Thread     t          = new Thread(() =>
            {
                try
                {
                    var NuGet = Package.Instance.NuGet;
                    if (!NuGet.IsUserConsentGranted())
                    {
                        Package.WriteMessage("Ice Builder cannot download the required NuGet packages because " +
                                             "\"Allow NuGet to download missing packages\" is disabled");
                        dispatcher.Invoke(new Action(() => progressCallback.Finished()));
                        return;
                    }

                    var DTE     = Package.Instance.DTE;
                    var builder = Package.Instance;
                    int i       = 0;
                    int total   = projects.Count;
                    foreach (var entry in projects)
                    {
                        var project    = entry.Value;
                        var dteProject = project.GetDTEProject();
                        var uniqueName = dteProject.UniqueName;
                        var name       = entry.Key;
                        i++;
                        if (progressCallback.Canceled)
                        {
                            break;
                        }

                        dispatcher.Invoke(
                            new Action(() =>
                        {
                            progressCallback.ReportProgress(name, i);
                        }));

                        try
                        {
                            NuGet.Restore(dteProject);
                        }
                        catch (Exception ex)
                        {
                            Package.WriteMessage(
                                string.Format("\nNuGet package restore failed:\n{0}\n", ex.Message));
                            dispatcher.Invoke(new Action(() => progressCallback.Finished()));
                            break;
                        }

                        if (!NuGet.IsPackageInstalled(dteProject, Package.NuGetBuilderPackageId))
                        {
                            try
                            {
                                DTE.StatusBar.Text = string.Format("Installing NuGet package {0} in project {1}",
                                                                   Package.NuGetBuilderPackageId, name);
                                NuGet.InstallLatestPackage(dteProject, Package.NuGetBuilderPackageId);
                            }
                            catch (Exception ex)
                            {
                                Package.WriteMessage(
                                    string.Format("\nNuGet package zeroc.icebuilder.msbuild install failed:\n{0}\n", ex.Message));
                                dispatcher.Invoke(new Action(() => progressCallback.Finished()));
                                break;
                            }
                        }

                        IceBuilderProjectType projectType = IsIceBuilderEnabled(project);
                        if (projectType != IceBuilderProjectType.None)
                        {
                            bool cpp           = projectType == IceBuilderProjectType.CppProjectType;
                            DTE.StatusBar.Text = string.Format("Upgrading project {0} Ice Builder settings", project.GetDTEProject().UniqueName);

                            var fullPath    = project.GetProjectFullPath();
                            var assemblyDir = project.GetEvaluatedProperty("IceAssembliesDir");
                            var outputDir   = project.GetEvaluatedProperty("IceBuilderOutputDir");

                            var outputDirUnevaluated       = project.GetPropertyWithDefault("IceBuilderOutputDir", "generated");
                            var sourceExt                  = project.GetPropertyWithDefault("IceBuilderSourceExt", "cpp");
                            var headerOutputDirUnevaluated = project.GetProperty("IceBuilderHeaderOutputDir");
                            var headerExt                  = project.GetPropertyWithDefault("IceBuilderHeaderExt", "h");

                            var cppOutputDir       = new List <string>();
                            var cppHeaderOutputDir = new List <string>();
                            if (cpp)
                            {
                                var waitEvent = new ManualResetEvent(false);
                                dispatcher.BeginInvoke(new Action(() =>
                                {
                                    foreach (EnvDTE.Configuration configuration in dteProject.ConfigurationManager)
                                    {
                                        cppOutputDir.Add(Package.Instance.VCUtil.Evaluate(configuration, outputDirUnevaluated));
                                        if (string.IsNullOrEmpty(headerOutputDirUnevaluated))
                                        {
                                            cppHeaderOutputDir.Add(Package.Instance.VCUtil.Evaluate(configuration, outputDirUnevaluated));
                                        }
                                        else
                                        {
                                            cppHeaderOutputDir.Add(Package.Instance.VCUtil.Evaluate(configuration, headerOutputDirUnevaluated));
                                        }
                                    }
                                    waitEvent.Set();
                                }));
                                waitEvent.WaitOne();
                            }
                            else
                            {
                                foreach (VSLangProj80.Reference3 r in dteProject.GetProjectRererences())
                                {
                                    if (Package.AssemblyNames.Contains(r.Name))
                                    {
                                        project.UpdateProject((MSProject msproject) =>
                                        {
                                            var item = msproject.AllEvaluatedItems.FirstOrDefault(referenceItem =>
                                                                                                  referenceItem.ItemType.Equals("Reference") &&
                                                                                                  referenceItem.EvaluatedInclude.Split(",".ToCharArray()).ElementAt(0).Equals(r.Name));
                                            if (item != null)
                                            {
                                                if (item.HasMetadata("HintPath"))
                                                {
                                                    var hintPath = item.GetMetadata("HintPath").UnevaluatedValue;
                                                    if (hintPath.Contains("$(IceAssembliesDir)"))
                                                    {
                                                        hintPath = hintPath.Replace("$(IceAssembliesDir)",
                                                                                    FileUtil.RelativePath(Path.GetDirectoryName(r.ContainingProject.FullName), assemblyDir));
                                                        //
                                                        // If the HintPath points to the NuGet zeroc.ice.net package we upgrade it to not
                                                        // use IceAssembliesDir otherwise we remove it
                                                        if (hintPath.Contains("packages\\zeroc.ice.net"))
                                                        {
                                                            item.SetMetadataValue("HintPath", hintPath);
                                                        }
                                                        else
                                                        {
                                                            item.RemoveMetadata("HintPath");
                                                        }
                                                    }
                                                }
                                            }
                                        });
                                    }
                                }
                            }

                            project.UpdateProject((MSProject msproject) =>
                            {
                                MSBuildUtils.UpgradeProjectImports(msproject);
                                MSBuildUtils.UpgradeProjectProperties(msproject, cpp);
                                MSBuildUtils.RemoveIceBuilderFromProject(msproject, true);
                                MSBuildUtils.UpgradeProjectItems(msproject);
                                MSBuildUtils.UpgradeCSharpGeneratedItems(msproject, outputDir);
                                foreach (var d in cppOutputDir)
                                {
                                    MSBuildUtils.UpgradeGeneratedItems(msproject, d, sourceExt, "ClCompile");
                                }

                                foreach (var d in cppHeaderOutputDir)
                                {
                                    MSBuildUtils.UpgradeGeneratedItems(msproject, d, headerExt, "ClInclude");
                                }

                                var propertyGroup = msproject.Xml.PropertyGroups.FirstOrDefault(group => group.Label.Equals("IceBuilder"));
                                if (propertyGroup != null)
                                {
                                    propertyGroup.Parent.RemoveChild(propertyGroup);
                                }

                                if (cpp)
                                {
                                    propertyGroup       = msproject.Xml.AddPropertyGroup();
                                    propertyGroup.Label = "IceBuilder";
                                    propertyGroup.AddProperty("IceCppMapping", "cpp98");
                                }
                            });

                            builder.ReloadProject(project);
                        }
                    }
                    dispatcher.BeginInvoke(new Action(() => progressCallback.Finished()));
                }
                catch (Exception ex)
                {
                    dispatcher.BeginInvoke(new Action(() => progressCallback.Canceled = true));
                    Package.UnexpectedExceptionWarning(ex);
                }
            });

            t.Start();
        }
        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);
                }
            }
        }
 public static void SetProperty(EnvDTE.Project project, String name, String value)
 {
     MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(project.FullName), "IceBuilder", name, value);
 }
        public bool Build(IVsProject p, BuildCallback buildCallback, BuildLogger buildLogger)
        {
            MSBuildProject project = MSBuildUtils.LoadedProject(ProjectUtil.GetProjectFullPath(p), DTEUtil.IsCppProject(p), 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
            {
                try
                {
                    Dictionary <string, string> properties = new Dictionary <string, string>();
                    String platform = buildCallback.ProjectConfiguration.PlatformName;
                    properties["Platform"]      = platform.Equals("Any CPU") ? "AnyCPU" : platform;
                    properties["Configuration"] = buildCallback.ProjectConfiguration.ConfigurationName;

                    BuildRequestData buildRequest = new BuildRequestData(
                        ProjectUtil.GetProjectFullPath(p),
                        properties,
                        null,
                        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;
                }
            }
        }
        public static string GetEvaluatedProperty(IVsProject project, string name, string defaultValue)
        {
            string value = MSBuildUtils.GetEvaluatedProperty(MSBuildUtils.LoadedProject(GetProjectFullPath(project), DTEUtil.IsCppProject(project), true), name);

            return(string.IsNullOrEmpty(value) ? defaultValue : value);
        }
        public static String GetProperty(EnvDTE.Project project, String name, String defaultValue)
        {
            String value = MSBuildUtils.GetProperty(MSBuildUtils.LoadedProject(project.FullName), name);

            return(String.IsNullOrEmpty(value) ? defaultValue : value);
        }
 public static void SetProperty(IVsProject project, string name, string value)
 {
     MSBuildUtils.SetProperty(MSBuildUtils.LoadedProject(GetProjectFullPath(project), DTEUtil.IsCppProject(project), true), "IceBuilder", name, value);
 }
 public static bool IsIceBuilderEnabled(EnvDTE.Project project)
 {
     return(project != null && !String.IsNullOrEmpty(project.FullName) &&
            (IsCppProject(project) || IsCSharpProject(project)) &&
            MSBuildUtils.IsIceBuilderEnabeld(MSBuildUtils.LoadedProject(project.FullName)));
 }
        public static void Upgrade(Dictionary <string, IVsProject> projects, UpgradeProgressCallback progressCallback)
        {
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
            Thread     t          = new Thread(() =>
            {
                var NuGet   = Package.Instance.NuGet;
                var DTE     = Package.Instance.DTE;
                var builder = Package.Instance;
                int i       = 0;
                int total   = projects.Count;
                foreach (var entry in projects)
                {
                    var project    = entry.Value;
                    var dteProject = project.GetDTEProject();
                    var name       = entry.Key;
                    i++;
                    if (progressCallback.Canceled)
                    {
                        break;
                    }

                    dispatcher.Invoke(
                        new Action(() =>
                    {
                        progressCallback.ReportProgress(name, i);
                    }));

                    NuGet.Restore(dteProject);
                    if (!NuGet.IsPackageInstalled(dteProject, Package.NuGetBuilderPackageId))
                    {
                        DTE.StatusBar.Text = string.Format("Installing NuGet package {0} in project {1}",
                                                           Package.NuGetBuilderPackageId, name);
                        NuGet.InstallLatestPackage(dteProject, Package.NuGetBuilderPackageId);
                    }

                    IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);
                    if (projectType != IceBuilderProjectType.None)
                    {
                        bool cpp           = projectType == IceBuilderProjectType.CppProjectType;
                        DTE.StatusBar.Text = string.Format("Upgrading project {0} Ice Builder settings", project.GetDTEProject().UniqueName);
                        var msproject      = project.GetMSBuildProject();
                        var fullPath       = ProjectUtil.GetProjectFullPath(project);
                        var assemblyDir    = ProjectUtil.GetEvaluatedProperty(project, "IceAssembliesDir");
                        if (projectType == IceBuilderProjectType.CsharpProjectType)
                        {
                            foreach (VSLangProj80.Reference3 r in dteProject.GetProjectRererences())
                            {
                                if (Package.AssemblyNames.Contains(r.Name))
                                {
                                    var item = msproject.AllEvaluatedItems.FirstOrDefault(referenceItem =>
                                                                                          referenceItem.ItemType.Equals("Reference") &&
                                                                                          referenceItem.EvaluatedInclude.Split(",".ToCharArray()).ElementAt(0).Equals(r.Name));
                                    if (item != null)
                                    {
                                        if (item.HasMetadata("HintPath"))
                                        {
                                            var hintPath = item.GetMetadata("HintPath").UnevaluatedValue;
                                            if (hintPath.Contains("$(IceAssembliesDir)"))
                                            {
                                                hintPath = hintPath.Replace("$(IceAssembliesDir)",
                                                                            FileUtil.RelativePath(Path.GetDirectoryName(r.ContainingProject.FullName), assemblyDir));
                                                //
                                                // If the HintPath points to the NuGet zeroc.ice.net package we upgrade it to not
                                                // use IceAssembliesDir otherwise we remove it
                                                if (hintPath.Contains("packages\\zeroc.ice.net"))
                                                {
                                                    item.SetMetadataValue("HintPath", hintPath);
                                                }
                                                else
                                                {
                                                    item.RemoveMetadata("HintPath");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        bool modified = MSBuildUtils.UpgradeProjectImports(msproject);
                        modified      = MSBuildUtils.UpgradeProjectProperties(msproject, cpp) || modified;
                        modified      = MSBuildUtils.RemoveIceBuilderFromProject(msproject, true) || modified;
                        modified      = MSBuildUtils.UpgradeProjectItems(msproject, cpp) || modified;

                        if (modified)
                        {
                            builder.SaveProject(project);
                        }
                    }
                }
                dispatcher.BeginInvoke(new Action(() => progressCallback.Finished()));
            });

            t.Start();
        }
 public static bool IsCSharpProject(IVsProject p)
 {
     return(ProjectUtil.GetProjecTypeGuid(p).Equals(csharpProjectGUID) &&
            MSBuildUtils.IsCSharpProject(p.GetMSBuildProject(true)));
 }
        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);
            }
        }