Ejemplo n.º 1
0
        void convertButton_Click(object sender, RoutedEventArgs e)
        {
            Core.AnalyticsMonitorService.TrackFeature(GetType(), "convertButton_Click");

            CompilerVersion selectedCompiler  = newVersionComboBox.SelectedValue as CompilerVersion;
            TargetFramework selectedFramework = newFrameworkComboBox.SelectedValue as TargetFramework;

            if (selectedCompiler is UnchangedCompilerVersion)
            {
                selectedCompiler = null;
            }
            if (selectedFramework != null)
            {
                // Show dialog for picking target frameworks for portable library.
                // This also handles UnchangedTargetFramework
                selectedFramework = selectedFramework.PickFramework(listView.SelectedItems.Cast <Entry>().Select(entry => entry.Project).ToList());
            }


            foreach (Entry entry in listView.SelectedItems)
            {
                try {
                    entry.UpgradeProject(selectedCompiler, selectedFramework);
                } catch (ProjectUpgradeException ex) {
                    Core.MessageService.ShowError("Cannot upgrade '" + entry.Name + "': " + ex.Message);
                    break;
                }
            }

            solution.Save();
            UpdateCompilerComboBox();
        }
        void convertButton_Click(object sender, RoutedEventArgs e)
        {
            Core.AnalyticsMonitorService.TrackFeature(GetType(), "convertButton_Click");

            CompilerVersion selectedCompiler  = newVersionComboBox.SelectedValue as CompilerVersion;
            TargetFramework selectedFramework = newFrameworkComboBox.SelectedValue as TargetFramework;

            if (selectedCompiler is UnchangedCompilerVersion)
            {
                selectedCompiler = null;
            }
            if (selectedFramework is UnchangedTargetFramework)
            {
                selectedFramework = null;
            }


            foreach (Entry entry in listView.SelectedItems)
            {
                try {
                    entry.UpgradeProject(selectedCompiler, selectedFramework);
                } catch (ProjectUpgradeException ex) {
                    Core.MessageService.ShowError("Cannot upgrade '" + entry.Name + "': " + ex.Message);
                    break;
                }
            }

            solution.Save();
            UpdateCompilerComboBox();
        }
Ejemplo n.º 3
0
        void UpdateConvertButtonEnabled()
        {
            CompilerVersion selectedCompiler  = newVersionComboBox.SelectedValue as CompilerVersion;
            TargetFramework selectedFramework = newFrameworkComboBox.SelectedValue as TargetFramework;

            bool changingCompiler  = false;
            bool changingFramework = false;

            if (!(selectedCompiler is UnchangedCompilerVersion))
            {
                foreach (Entry entry in listView.SelectedItems)
                {
                    if (!object.Equals(entry.CompilerVersion, selectedCompiler))
                    {
                        changingCompiler = true;
                    }
                }
            }
            if (!(selectedFramework is UnchangedTargetFramework))
            {
                foreach (Entry entry in listView.SelectedItems)
                {
                    if (!object.Equals(entry.TargetFramework, selectedFramework))
                    {
                        changingFramework = true;
                    }
                }
            }

            convertButton.IsEnabled = selectedCompiler != null && selectedFramework != null && (changingCompiler || changingFramework);
        }
Ejemplo n.º 4
0
            public void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
            {
                this.Project.UpgradeProject(newVersion, newFramework);

                this.CompilerVersion = this.Project.CurrentCompilerVersion;
                this.TargetFramework = this.Project.CurrentTargetFramework;
                OnPropertyChanged("CompilerVersionName");
                OnPropertyChanged("TargetFrameworkName");
            }
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            CompilerVersion v = (CompilerVersion)obj;

            return(this.MSBuildVersion == v.MSBuildVersion);
        }
 public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
 {
     PortableTargetFramework newFx = newFramework as PortableTargetFramework;
     if (newFx != null) {
         // Convert to portable library
         SD.AnalyticsMonitor.TrackFeature(GetType(), "ConvertToPortableLibrary");
         var project = (CompilableProject)Project;
         lock (project.SyncRoot) {
             var oldTargetFramework = project.CurrentTargetFramework;
             if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) {
                 project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor;
             }
             project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true);
             project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
             // Convert <Imports>
             project.PerformUpdateOnProjectFile(
                 delegate {
                     foreach (var import in project.MSBuildProjectFile.Imports) {
                         if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalCSharpTargets, StringComparison.OrdinalIgnoreCase)) {
                             import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableCSharpTargets;
                             break;
                         } else if (import.Project.EndsWith(PortableLibraryProjectBehavior.NormalVBTargets, StringComparison.OrdinalIgnoreCase)) {
                             import.Project = PortableLibraryProjectBehavior.PortableTargetsPath + PortableLibraryProjectBehavior.PortableVBTargets;
                             break;
                         }
                     }
                 });
             // Remove references
             foreach (var referenceItem in project.GetItemsOfType(ItemType.Reference).ToArray()) {
                 // get short assembly name:
                 string assemblyName = referenceItem.Include;
                 if (assemblyName.IndexOf(',') >= 0)
                     assemblyName = assemblyName.Substring(0, assemblyName.IndexOf(','));
                 if (oldTargetFramework.ReferenceAssemblies.Any(fullName => string.Equals(fullName.ShortName, assemblyName, StringComparison.OrdinalIgnoreCase))) {
                     // If it's a framework assembly, remove the reference
                     // (portable libraries automatically reference all available framework assemblies)
                     ProjectService.RemoveProjectItem(project, referenceItem);
                 }
             }
             project.AddProjectType(ProjectTypeGuids.PortableLibrary);
             project.Save();
             ProjectBrowserPad.RefreshViewAsync();
         }
     } else {
         base.UpgradeProject(newVersion, newFramework);
     }
 }
Ejemplo n.º 7
0
        void UpdateCompilerComboBox()
        {
            if (listView.SelectedItems.Count > 0)
            {
                // Fetch list of available compiler versions
                HashSet <CompilerVersion> availableVersionsSet = new HashSet <CompilerVersion>();
                HashSet <CompilerVersion> currentVersions      = new HashSet <CompilerVersion>();
                foreach (Entry entry in listView.SelectedItems)
                {
                    if (entry.CompilerVersion != null)
                    {
                        currentVersions.Add(entry.CompilerVersion);
                    }
                    availableVersionsSet.AddRange(entry.Project.GetAvailableCompilerVersions());
                }
                List <CompilerVersion> availableVersions = availableVersionsSet.OrderBy(n => n.MSBuildVersion).ThenBy(n => n.DisplayName).ToList();
                if (currentVersions.Count != 1)
                {
                    availableVersions.Insert(0, new UnchangedCompilerVersion());
                }
                // Assign available versions to newVersionComboBox
                // Unless the user has already chosen a version, automatically set the selection to the
                // current version of the chosen projects, or to 'do not change' if there are different
                // current versions.
                newCompilerSelectionChangingByCode = true;
                newVersionComboBox.ItemsSource     = availableVersions;

                CompilerVersion oldSelectedVersion = newVersionComboBox.SelectedValue as CompilerVersion;
                if (!newCompilerSelectionSetByUser || oldSelectedVersion == null)
                {
                    newCompilerSelectionSetByUser = false;
                    if (currentVersions.Count == 1)
                    {
                        newVersionComboBox.SelectedValue = currentVersions.Single();
                    }
                    else
                    {
                        newVersionComboBox.SelectedValue = new UnchangedCompilerVersion();
                    }
                }
                newCompilerSelectionChangingByCode = false;
                UpdateTargetFrameworkComboBox();
            }
        }
		public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
		{
			var project = (CompilableProject)Project;
			var newFx = newFramework as PortableTargetFramework;
			if (newFramework != null && newFx == null) {
				// convert to normal .NET project (not portable)
				SD.AnalyticsMonitor.TrackFeature(GetType(), "DowngradePortableLibrary");
				project.PerformUpdateOnProjectFile(
					delegate {
						foreach (var import in project.MSBuildProjectFile.Imports) {
							if (import.Project.EndsWith(PortableCSharpTargets, StringComparison.OrdinalIgnoreCase)) {
								import.Project = NormalTargetsPath + NormalCSharpTargets;
								break;
							} else if (import.Project.EndsWith(PortableVBTargets, StringComparison.OrdinalIgnoreCase)) {
								import.Project = NormalTargetsPath + NormalVBTargets;
								break;
							}
						}
					});
				project.RemoveProjectType(ProjectTypeGuids.PortableLibrary);
				AddReferenceIfNotExists("System");
				AddReferenceIfNotExists("System.Xml");
				if (newFramework.IsBasedOn(TargetFramework.Net35) || newFramework.IsBasedOn(TargetFramework.Net35Client))
					AddReferenceIfNotExists("System.Core");
				base.UpgradeProject(newVersion, newFramework);
				return;
			}
			lock (project.SyncRoot) {
				if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) {
					project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor;
				}
				if (newFx != null) {
					project.SetProperty(null, null, "TargetFrameworkProfile", newFx.TargetFrameworkProfile, PropertyStorageLocations.Base, true);
					project.SetProperty(null, null, "TargetFrameworkVersion", newFx.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
				}
				project.Save();
				ProjectBrowserPad.RefreshViewAsync();
			}
		}
Ejemplo n.º 9
0
        void convertButton_Click(object sender, RoutedEventArgs e)
        {
            Core.AnalyticsMonitorService.TrackFeature(GetType(), "convertButton_Click");

            CompilerVersion selectedCompiler  = newVersionComboBox.SelectedValue as CompilerVersion;
            TargetFramework selectedFramework = newFrameworkComboBox.SelectedValue as TargetFramework;

            if (selectedCompiler is UnchangedCompilerVersion)
            {
                selectedCompiler = null;
            }
            if (selectedFramework is UnchangedTargetFramework)
            {
                selectedFramework = null;
            }


            foreach (Entry entry in listView.SelectedItems)
            {
                entry.UpgradeProject(selectedCompiler, selectedFramework);
            }
            solution.Save();
            UpdateCompilerComboBox();
        }
Ejemplo n.º 10
0
        void UpdateTargetFrameworkComboBox()
        {
            // Determine the available target frameworks
            bool            doNotChangeAllowed;
            CompilerVersion selectedCompiler = newVersionComboBox.SelectedValue as CompilerVersion;

            if (selectedCompiler is UnchangedCompilerVersion)
            {
                selectedCompiler = null;
            }

            // Calculate the intersection of available frameworks for all selected projects:
            HashSet <TargetFramework> availableFrameworkSet = null;

            foreach (Entry entry in listView.SelectedItems)
            {
                var entryFrameworks = entry.Project.GetAvailableTargetFrameworks()
                                      .Where(fx => fx.IsCompatibleWith(selectedCompiler ?? entry.CompilerVersion));
                if (availableFrameworkSet == null)
                {
                    availableFrameworkSet = new HashSet <TargetFramework>(entryFrameworks);
                }
                else
                {
                    availableFrameworkSet.IntersectWith(entryFrameworks);
                }
            }

            // Allow do not change on target framework if all current frameworks are supported
            // by the new compiler.
            doNotChangeAllowed = true;
            foreach (Entry entry in listView.SelectedItems)
            {
                doNotChangeAllowed &= availableFrameworkSet.Contains(entry.TargetFramework);
            }

            List <TargetFramework> availableFrameworks = availableFrameworkSet.ToList();

            availableFrameworks.Sort((a, b) => a.DisplayName.CompareTo(b.DisplayName));
            if (doNotChangeAllowed)
            {
                availableFrameworks.Insert(0, new UnchangedTargetFramework());
            }

            // detect whether all projects use a single framework
            TargetFramework frameworkUsedByAllProjects            = null;
            bool            frameworkUsedByAllProjectsInitialized = false;

            foreach (Entry entry in listView.SelectedItems)
            {
                if (!frameworkUsedByAllProjectsInitialized)
                {
                    frameworkUsedByAllProjects            = entry.TargetFramework;
                    frameworkUsedByAllProjectsInitialized = true;
                }
                else
                {
                    if (!object.Equals(frameworkUsedByAllProjects, entry.TargetFramework))
                    {
                        frameworkUsedByAllProjects = null;
                    }
                }
            }

            // if projects use different frameworks, preselect "<do not change>", if possible
            if (frameworkUsedByAllProjects == null && doNotChangeAllowed)
            {
                frameworkUsedByAllProjects = availableFrameworks[0];
            }

            newFrameworkSelectionChangingByCode = true;
            newFrameworkComboBox.ItemsSource    = availableFrameworks;

            TargetFramework oldSelectedFramework = newFrameworkComboBox.SelectedValue as TargetFramework;

            if (!newFrameworkSelectionSetByUser || oldSelectedFramework == null)
            {
                newFrameworkSelectionSetByUser = false;
                if (availableFrameworks.Contains(frameworkUsedByAllProjects))
                {
                    newFrameworkComboBox.SelectedValue = frameworkUsedByAllProjects;
                }
            }
            newFrameworkSelectionChangingByCode = false;
            UpdateConvertButtonEnabled();
        }
Ejemplo n.º 11
0
		public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
		{
			if (!Project.ReadOnly) {
				lock (Project.SyncRoot) {
					TargetFramework oldFramework = Project.CurrentTargetFramework;
					if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) {
						Project.SetToolsVersion(newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor);
					}
					if (newFramework != null) {
						UpdateAppConfig(newFramework);
						
						ClientProfileTargetFramework clientProfile = newFramework as ClientProfileTargetFramework;
						if (clientProfile != null) {
							newFramework = clientProfile.FullFramework;
							((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", "Client", PropertyStorageLocations.Base, true);
						} else {
							((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", "", PropertyStorageLocations.Base, true);
						}
						((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkVersion", newFramework.Name, PropertyStorageLocations.Base, true);
						
						if (oldFramework is ClientProfileTargetFramework)
							oldFramework = ((ClientProfileTargetFramework)oldFramework).FullFramework;
						
						if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net35) && newFramework.IsBasedOn(TargetFramework.Net35))
							AddDotnet35References();
						else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net35) && !newFramework.IsBasedOn(TargetFramework.Net35))
							RemoveDotnet35References();
						
						if (oldFramework != null && !oldFramework.IsBasedOn(TargetFramework.Net40) && newFramework.IsBasedOn(TargetFramework.Net40))
							AddDotnet40References();
						else if (oldFramework != null && oldFramework.IsBasedOn(TargetFramework.Net40) && !newFramework.IsBasedOn(TargetFramework.Net40))
							RemoveDotnet40References();
					}
					AddOrRemoveExtensions();
					Project.Save();
					ResXConverter.UpdateResourceFiles(Project);
				}
			}
		}
Ejemplo n.º 12
0
 public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
 {
     if (this.next != null)
         next.UpgradeProject(newVersion, newFramework);
 }
Ejemplo n.º 13
0
        void UpdateTargetFrameworkComboBox()
        {
            // Determine the available target frameworks
            List <TargetFramework> availableFrameworks;
            bool            doNotChangeAllowed;
            CompilerVersion selectedCompiler = newVersionComboBox.SelectedValue as CompilerVersion;

            if (selectedCompiler == null || selectedCompiler is UnchangedCompilerVersion)
            {
                // no entries or "Do not change" selected
                // -> available target frameworks is the intersection of all compiler's target framework,
                // and "Do not change" is always available

                availableFrameworks = (
                    from Entry entry in listView.SelectedItems
                    where entry.CompilerVersion != null
                    from fx in entry.CompilerVersion.GetSupportedTargetFrameworks()
                    select fx
                    ).Distinct().ToList();

                doNotChangeAllowed = true;
            }
            else
            {
                // Specific compiler version is selected
                // Show that compiler's target frameworks
                availableFrameworks = selectedCompiler.GetSupportedTargetFrameworks().ToList();
                // Allow do not change on target framework if all current frameworks are supported
                // by the new compiler.
                doNotChangeAllowed = true;
                foreach (Entry entry in listView.SelectedItems)
                {
                    doNotChangeAllowed &= availableFrameworks.Contains(entry.TargetFramework);
                }
            }

            availableFrameworks.Sort((a, b) => a.DisplayName.CompareTo(b.DisplayName));
            if (doNotChangeAllowed)
            {
                availableFrameworks.Insert(0, new UnchangedTargetFramework());
            }

            // detect whether all projects use a single framework
            TargetFramework frameworkUsedByAllProjects            = null;
            bool            frameworkUsedByAllProjectsInitialized = false;

            foreach (Entry entry in listView.SelectedItems)
            {
                if (!frameworkUsedByAllProjectsInitialized)
                {
                    frameworkUsedByAllProjects            = entry.TargetFramework;
                    frameworkUsedByAllProjectsInitialized = true;
                }
                else
                {
                    if (!object.Equals(frameworkUsedByAllProjects, entry.TargetFramework))
                    {
                        frameworkUsedByAllProjects = null;
                    }
                }
            }

            // if projects use different frameworks, preselect "<do not change>", if possible
            if (frameworkUsedByAllProjects == null && doNotChangeAllowed)
            {
                frameworkUsedByAllProjects = availableFrameworks[0];
            }

            newFrameworkSelectionChangingByCode = true;
            newFrameworkComboBox.ItemsSource    = availableFrameworks;

            TargetFramework oldSelectedFramework = newFrameworkComboBox.SelectedValue as TargetFramework;

            if (!newFrameworkSelectionSetByUser || oldSelectedFramework == null)
            {
                newFrameworkSelectionSetByUser = false;
                if (availableFrameworks.Contains(frameworkUsedByAllProjects))
                {
                    newFrameworkComboBox.SelectedValue = frameworkUsedByAllProjects;
                }
            }
            newFrameworkSelectionChangingByCode = false;
            UpdateConvertButtonEnabled();
        }
Ejemplo n.º 14
0
			public void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
			{
				this.Project.UpgradeProject(newVersion, newFramework);
				
				this.CompilerVersion = this.Project.CurrentCompilerVersion;
				this.TargetFramework = this.Project.CurrentTargetFramework;
				OnPropertyChanged("CompilerVersionName");
				OnPropertyChanged("TargetFrameworkName");
			}
Ejemplo n.º 15
0
            public Entry(IUpgradableProject project)
            {
                this.Project = project;

                this.CompilerVersion = project.CurrentCompilerVersion;
                this.TargetFramework = project.CurrentTargetFramework;
            }
Ejemplo n.º 16
0
		public virtual void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
		{
			GetOrCreateBehavior().UpgradeProject(newVersion, newFramework);
		}
		public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
		{
			throw new NotSupportedException();
		}
Ejemplo n.º 18
0
		public virtual bool IsCompatibleWith(CompilerVersion compilerVersion)
		{
			return MinimumMSBuildVersion <= compilerVersion.MSBuildVersion;
		}
Ejemplo n.º 19
0
        public override void UpgradeProject(CompilerVersion newVersion, TargetFramework newFramework)
        {
            if (!Project.IsReadOnly) {
                lock (Project.SyncRoot) {
                    TargetFramework oldFramework = Project.CurrentTargetFramework;
                    if (newVersion != null && GetAvailableCompilerVersions().Contains(newVersion)) {
                        Project.ToolsVersion = newVersion.MSBuildVersion.Major + "." + newVersion.MSBuildVersion.Minor;
                    }
                    if (newFramework != null) {
                        UpdateAppConfig(newFramework);

                        ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkVersion", newFramework.TargetFrameworkVersion, PropertyStorageLocations.Base, true);
                        ((MSBuildBasedProject)Project).SetProperty(null, null, "TargetFrameworkProfile", newFramework.TargetFrameworkProfile, PropertyStorageLocations.Base, true);

                        if (oldFramework != null && oldFramework.Version < Versions.V3_5 && newFramework.Version >= Versions.V3_5)
                            AddDotnet35References();
                        else if (oldFramework != null && oldFramework.Version >= Versions.V3_5 && newFramework.Version < Versions.V3_5)
                            RemoveDotnet35References();

                        if (oldFramework != null && oldFramework.Version < Versions.V4_0 && newFramework.Version >= Versions.V4_0)
                            AddDotnet40References();
                        else if (oldFramework != null && oldFramework.Version >= Versions.V4_0 && newFramework.Version < Versions.V4_0)
                            RemoveDotnet40References();
                    }
                    AddOrRemoveExtensions();
                    Project.Save();
                    ResXConverter.UpdateResourceFiles(Project);
                }
            }
        }