protected override void Execute()
        {
            var context = new SolutionContext(solutionExplorer);
            context.Initialize(solutionExplorer.Solution.ActiveProject);

            var viewModel = new AddPlatformImplementationViewModel();

            foreach (var platform in platformProvider.GetSupportedPlatforms())
                viewModel.Platforms.Add(platform);

            viewModel.IsSharedProjectEnabled = context.SharedProject == null;

            var view = new AddPlatformImplementationView();
            view.DataContext = viewModel;

            if (dialogService.ShowDialog(view) == true)
            {
                if (context.SharedProject == null && viewModel.UseSharedProject)
                {
                    context.SharedProject = solutionExplorer.Solution.UnfoldTemplate(
                        Constants.Templates.SharedProject, context.SharedProjectName);

                    // Move PCL items to the shared project
                    context.SelectedProject.Accept(
                        new MoveProjectItemsToProjectVisitor(context.SharedProject));
                }

                if (context.NuGetProject == null)
                {
                    context.NuGetProject = solutionExplorer.Solution.UnfoldTemplate(
                        Constants.Templates.NuGetPackage, context.NuGetProjectName, Constants.Language);
                }

                foreach (var selectedPlatform in viewModel.Platforms.Where(x => x.IsEnabled && x.IsSelected))
                {
                    var projectName = context.GetTargetProjectName(selectedPlatform);
                    var project = context.GetProjectNode(projectName);

                    if (project == null)
                        project = solutionExplorer.Solution.UnfoldTemplate(
                            Constants.Templates.GetPlatformTemplate(selectedPlatform.Id),
                            projectName);

                    if (context.SharedProject != null)
                        project.AddReference(context.SharedProject);

                    context.NuGetProject.AddReference(project);
                }
            }
        }
        public void RunFinished()
        {
            var solutionContext = new SolutionContext(solutionExplorer);

            solutionContext.BaseProjectName = SafeProjectName;

            if (ViewModel.UsePlatformSpecific)
            {
                solutionContext.SharedProject = solutionExplorer.Solution.UnfoldTemplate(
                    Constants.Templates.SharedProject,
                    SafeProjectName + "." + Constants.Suffixes.SharedProject);


                // HACK (NuGetTemplate): dteSolution2.GetProjectTemplate ("NuGet.Packaging.VisualStudio.Package", "NuGet")
                // is not working when "NuGet" is used as the language name
                // So for now we replicate the template for CS and set its visibility to hidden

                solutionContext.NuGetProject = solutionExplorer.Solution.UnfoldTemplate(
                    Constants.Templates.NuGetPackage,
                    SafeProjectName + "." + Constants.Suffixes.NuGetPackage);

                //solutionContext.NuGetProject = solutionExplorer.Solution.UnfoldTemplate(
                //	Constants.Templates.NuGetPackage,
                //	SafeProjectName + "." + Constants.Suffixes.NuGetPackage,
                //Constants.Language);

                foreach (var selectedPlatform in ViewModel.Platforms.Where(x => x.IsSelected))
                {
                    var platformProject = solutionExplorer.Solution.UnfoldTemplate(
                        Constants.Templates.GetPlatformTemplate(selectedPlatform.Id),
                        solutionContext.GetTargetProjectName(selectedPlatform));

                    var platformDteProject = platformProject.As <EnvDTE.Project>();

                    if (!packageInstallerServices.IsBuildPackagingNuGetInstalled(platformDteProject))
                    {
                        packageInstaller.InstallBuildPackagingNuget(platformDteProject);
                    }

                    platformProject.AddReference(solutionContext.SharedProject);
                    solutionContext.NuGetProject.AddReference(platformProject);
                }
            }
            else
            {
                solutionContext.SharedProject = solutionExplorer.Solution.UnfoldTemplate(
                    Constants.Templates.PortableClassLibrary,
                    SafeProjectName);
            }
        }
예제 #3
0
		public void RunFinished()
		{
			var solutionContext = new SolutionContext(solutionExplorer);
			solutionContext.BaseProjectName = WizardModel.SafeProjectName;

			solutionContext.SharedProject = solutionExplorer.Solution.UnfoldTemplate(
				Constants.Templates.SharedProject,
				WizardModel.SafeProjectName + "." + Constants.Suffixes.SharedProject);

			solutionContext.NuGetProject = solutionExplorer.Solution.UnfoldTemplate(
				Constants.Templates.NuGetPackage,
				WizardModel.SafeProjectName + "." + Constants.Suffixes.NuGetPackage,
				Constants.Language);

			foreach (var selectedPlatform in ViewModel.Platforms.Where(x => x.IsSelected))
			{
				var platformProject = solutionExplorer.Solution.UnfoldTemplate(
					Constants.Templates.GetPlatformTemplate(selectedPlatform.Id),
					solutionContext.GetTargetProjectName (selectedPlatform));

				platformProject.AddReference(solutionContext.SharedProject);
				solutionContext.NuGetProject.AddReference(platformProject);
			}
		}
        protected override void Execute()
        {
            var context = new SolutionContext(solutionExplorer);

            context.Initialize(solutionExplorer.Solution.ActiveProject);

            var viewModel = new AddPlatformImplementationViewModel();

            foreach (var platform in platformProvider.GetSupportedPlatforms())
            {
                platform.IsEnabled = context.GetProjectNode(platform) == null;
                viewModel.Platforms.Add(platform);
            }

            if (!viewModel.Platforms.Any(x => x.IsEnabled))
            {
                MessageBox.Show(
                    "The available platform projects are already present in the current solution. Please select a different library or remove any of the platform projects.",
                    "Add Platform Implementation",
                    MessageBoxButton.OK,
                    MessageBoxImage.Exclamation);

                return;
            }

            viewModel.IsSharedProjectEnabled = context.SharedProject == null;

            var view = new AddPlatformImplementationView();

            view.DataContext = viewModel;

            if (dialogService.ShowDialog(view) == true)
            {
                if (context.SharedProject == null && viewModel.UseSharedProject)
                {
                    context.SharedProject = solutionExplorer.Solution.UnfoldTemplate(
                        Constants.Templates.SharedProject, context.SharedProjectName);
                }

                if (context.NuGetProject == null)
                {
                    context.NuGetProject = solutionExplorer.Solution.UnfoldTemplate(
                        Constants.Templates.NuGetPackage, context.NuGetProjectName);
                }

                context.NuGetProject.AddReference(context.SelectedProject);

                EnsureBuildPackagingNugetInstalled(context.SelectedProject);

                foreach (var selectedPlatform in viewModel.Platforms.Where(x => x.IsEnabled && x.IsSelected))
                {
                    var projectName = context.GetTargetProjectName(selectedPlatform);
                    var project     = context.GetProjectNode(projectName);

                    if (project == null)
                    {
                        project = solutionExplorer.Solution.UnfoldTemplate(
                            Constants.Templates.GetPlatformTemplate(selectedPlatform.Id),
                            projectName);
                    }

                    EnsureBuildPackagingNugetInstalled(project);

                    if (context.SharedProject != null && viewModel.UseSharedProject)
                    {
                        project.AddReference(context.SharedProject);
                    }

                    context.NuGetProject.AddReference(project);
                }
            }
        }