public void LoadProjects()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            using (var solutionProcessor = new SolutionProcessor(mCurrentSolution))
            {
                var projVers = solutionProcessor.BuildVersions(mCurrentSolution);


                ShowUnloadedWarning = solutionProcessor.DetectedUnloadedProjects;
                FailedProjects      = solutionProcessor.FailedProjects;

                foreach (var item in projVers.OrderBy(projver => projver.Name))
                {
                    this.Items.Add(item);
                }


                ShowIos     = projVers.HasIosMac;
                ShowAndroid = projVers.HasAndroid;

                Version outVersion = null;

                if (System.Version.TryParse(AssemblyVersion, out outVersion))
                {
                    if (ShowIos)
                    {
                        CocoaShortVersion = CocoaAppVersion.ToShortVersion(outVersion);
                    }

                    if (ShowAndroid)
                    {
                        AndroidBuild = AndroidAppVersion.ToBuild(outVersion);
                    }
                }
            }


            LoadAssVersion();

            LoadAssFileVersion();
        }
        public void ProcessUpdates()
        {
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                Version newVersion;
                Version fileVersion = null;

                //add support for dynamic build revision values
                var theVersion = (forceSemVer) ? $"{AssemblyMajor ?? "0"}.{AssemblyMinor ?? "0"}.{AssemblyBuild ?? "0"}" : this.AssemblyVersion;

                newVersion = new Version(theVersion);

                var newVersionValue = (newVersion.Revision == -1) ? $"{newVersion.Major}.{newVersion.Minor}.{newVersion.Build}.0" : newVersion.ToString();

                if (mSeparateVersions)
                {
                    var vers = (forceSemVer) ? $"{AssemblyFileMajor ?? "0"}.{AssemblyFileMinor ?? "0"}.{AssemblyFileBuild ?? "0"}" : this.FileVersion;

                    fileVersion = new Version(vers);
                }


                var _serviceProvider = new ServiceProvider(mApplication as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
                var _sln             = (IVsSolution)_serviceProvider.GetService(typeof(SVsSolution));

                if (_sln == null)
                {
                    throw new Exception("Unable to find the solution");
                }

                using (var solutionProcessor = new SolutionProcessor(mCurrentSolution))
                {
                    foreach (ProjectVersion ver in Items)
                    {
                        if (ver.Update)
                        {
                            if (ver.IsNewStyleProject == true)
                            {
                                solutionProcessor.UpdateProject(ver.RealProject, newVersion, fileVersion);
                            }
                            else
                            {
                                solutionProcessor.UpdateFile(ver.ProjectItem, newVersion, fileVersion);
                            }


                            if (UpdateClickOnce)
                            {
                                IVsHierarchy hiearachy = null;
                                _sln.GetProjectOfUniqueName(ver.RealProject.FullName, out hiearachy);

                                Guid aGuid;

                                _sln.GetGuidOfProject(hiearachy, out aGuid);

                                IVsBuildPropertyStorage buildPropStorage = (IVsBuildPropertyStorage)hiearachy;

                                string propValue;
                                buildPropStorage.GetPropertyValue("ApplicationVersion", "Debug", (uint)_PersistStorageType.PST_PROJECT_FILE, out propValue);

                                if (!String.IsNullOrWhiteSpace(propValue))
                                {
                                    var xmldoc = XDocument.Load(ver.RealProject.FullName);

                                    XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";

                                    bool hasChanged = false;
                                    foreach (var resource in xmldoc.Descendants(msbuild + "ApplicationVersion"))
                                    {
                                        string curVersion = resource.Value;

                                        if (!curVersion.Equals(this.AssemblyVersion))
                                        {
                                            resource.Value = newVersionValue;

                                            hasChanged = true;
                                        }
                                    }

                                    if (hasChanged)
                                    {
                                        var stP = mApplication.Solution.Properties.Item("StartupProject").Value;

                                        var stPName = ver.RealProject.Name;

                                        var aFileName = ver.RealProject.FullName;

                                        var _sln2 = (IVsSolution4)_serviceProvider.GetService(typeof(SVsSolution));

                                        if (_sln2 == null)
                                        {
                                            throw new Exception("Unable to access the solution");
                                        }

                                        _sln2.UnloadProject(aGuid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser);

                                        xmldoc.Save(aFileName);

                                        IVsHierarchy hiearachy2 = null;
                                        _sln.GetProjectOfUniqueName(aFileName, out hiearachy2);

                                        Guid aGuid2;

                                        _sln.GetGuidOfProject(hiearachy2, out aGuid2);

                                        if (aGuid != aGuid2)
                                        {
                                            Console.WriteLine("");
                                        }

                                        _sln2.ReloadProject(aGuid);

                                        if (stP.Equals(stPName))
                                        {
                                            mApplication.Solution.Properties.Item("StartupProject").Value = stPName;
                                        }
                                    }
                                }
                            }

                            if (ver.SecondaryProjectItem != null)
                            {
                                if (ver.IsCocoa == true)
                                {
                                    var secFile = ver.SecondaryProjectItem.FileNames[0];

                                    var aUpdater = new CocoaAppVersion()
                                    {
                                        FilePath = secFile
                                    };

                                    aUpdater.VersionOne = cocoaShortVersion;
                                    aUpdater.VersionTwo = newVersionValue;
                                    aUpdater.Update();
                                }
                                else if (ver.IsAndroid == true)
                                {
                                    var secFile = ver.SecondaryProjectItem.FileNames[0];

                                    var aUpdater = new AndroidAppVersion()
                                    {
                                        FilePath = secFile
                                    };

                                    aUpdater.VersionOne = androidBuild;
                                    aUpdater.VersionTwo = newVersionValue;
                                    aUpdater.Update();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
                //throw new Exception("One of the versions specified is not valid");
            }
        }
示例#3
0
        public void LoadProjects()
        {
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();



                using (var solutionProcessor = new SolutionProcessor(mCurrentSolution))
                {
                    solutionProcessor.OnLoadedProjects += (s, e) =>
                    {
                        TotalProjects = e;

                        LoadingProgressUpdated(this, null);
                    };

                    solutionProcessor.OnStartingProject += (s, e) =>
                    {
                        CurrentProject     = e.Item1;
                        CurrentProjectName = e.Item2;

                        LoadingProgressUpdated(this, null);
                    };

                    var projVers = solutionProcessor.BuildVersions(mCurrentSolution);
                    ShowUnloadedWarning = solutionProcessor.DetectedUnloadedProjects;
                    FailedProjects      = solutionProcessor.FailedProjects;

                    foreach (var item in projVers.OrderBy(projver => projver.Name))
                    {
                        this.Items.Add(item);
                    }


                    ShowIos     = projVers.HasIosMac;
                    ShowAndroid = projVers.HasAndroid;

                    Version outVersion = null;

                    if (System.Version.TryParse(AssemblyVersion, out outVersion))
                    {
                        if (ShowIos)
                        {
                            CocoaShortVersion = CocoaAppVersion.ToShortVersion(outVersion);
                        }

                        if (ShowAndroid)
                        {
                            AndroidBuild = AndroidAppVersion.ToBuild(outVersion);
                        }
                    }
                }


                LoadAssVersion();

                LoadAssFileVersion();

                IsLoaded = true;

                IsBusy = false;
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Error loading projects");
            }
        }