/// <summary>
        /// This event is fired after the project is saved. Runs a restore if the project was
        /// not reloaded.
        /// </summary>
        void ProjectTargetFrameworkChanged(object sender, ProjectTargetFrameworkChangedEventArgs e)
        {
            if (e.IsReload)
            {
                // Ignore. A restore will occur on reload elsewhere.
                return;
            }

            // Need to re-evaluate before restoring to ensure the implicit package references are correct after
            // the target framework has changed.
            RestorePackagesInProjectHandler.Run(Project, restoreTransitiveProjectReferences: true, reevaluateBeforeRestore: true);
        }
 void ProjectTargetFrameworkChanged(object sender, ProjectTargetFrameworkChangedEventArgs e)
 {
     if (e.Project.HasPackagesConfig())
     {
         var runner = new PackageCompatibilityRunner(e.Project);
         runner.Run();
     }
     else if (DotNetCoreNuGetProject.CanCreate(e.Project.DotNetProject))
     {
         // Ignore - .NET Core project target framework changes are handled
         // by the DotNetCoreProjectExtension.
     }
     else if (PackageReferenceNuGetProject.CanCreate(e.Project.DotNetProject))
     {
         RestorePackagesInProjectHandler.Run(e.Project.DotNetProject);
     }
 }
        /// <summary>
        /// Handle a new project being created and added to a new solution. In this case
        /// the NuGet packages should be restored. Need to avoid running a restore when
        /// a solution is being opened so check that project's parent solution is open in
        /// the IDE.
        /// </summary>
        protected override void OnBoundToSolution()
        {
            base.OnBoundToSolution();

            if (Project.Loading)
            {
                return;
            }

            if (IdeApp.ProjectOperations.CurrentSelectedSolution != Project.ParentSolution)
            {
                return;
            }

            if (ProjectNeedsRestore())
            {
                RestorePackagesInProjectHandler.Run(Project);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handle a new project being created and added to a new solution. In this case
        /// the NuGet packages should be restored. Need to avoid running a restore when
        /// a solution is being opened so check that project's parent solution is open in
        /// the IDE.
        /// </summary>
        protected override void OnBoundToSolution()
        {
            base.OnBoundToSolution();

            if (Project.Loading)
            {
                return;
            }

            if (!IdeApp.IsInitialized)
            {
                return;
            }

            if (IdeApp.ProjectOperations.CurrentSelectedSolution != Project.ParentSolution)
            {
                return;
            }

            if (!Project.NuGetAssetsFileExists())
            {
                RestorePackagesInProjectHandler.Run(Project);
            }
        }
 void RestoreNuGetPackages()
 {
     Runtime.AssertMainThread();
     RestorePackagesInProjectHandler.Run(Project);
 }
 void OnDotNetCoreProjectReloaded(ProjectReloadedEventArgs e)
 {
     DotNetCoreProjectBuilderMaintainer.OnProjectReload(e);
     RestorePackagesInProjectHandler.Run(e.NewProject.DotNetProject);
 }
Ejemplo n.º 7
0
        async Task <bool> Migrate(UnknownProject project, Solution solution, ProgressMonitor monitor)
        {
            FilePath projectFile;
            string   migrationFile;

            if (project == null)
            {
                migrationFile = solution.FileName;
            }
            else
            {
                projectFile   = project.FileName;
                migrationFile = Path.Combine(Path.GetDirectoryName(projectFile), "project.json");
            }
            if (DotNetCoreRuntime.IsMissing)
            {
                monitor.ReportError(GettextCatalog.GetString(".NET Core is not installed"));
                return(false);
            }

            var process = Runtime.ProcessService.StartProcess(
                DotNetCoreRuntime.FileName,
                $"migrate \"{migrationFile}\"",
                Path.GetDirectoryName(migrationFile),
                monitor.Log,
                monitor.Log,
                null);

            await process.Task;

            if (process.ExitCode > 0)
            {
                monitor.ReportError(GettextCatalog.GetString("An unspecified error occurred while running '{0}'", $"dotnet migrate({process.ExitCode})"));
                return(false);
            }

            if (project != null)
            {
                string newProjectFile;
                if (File.Exists(Path.ChangeExtension(projectFile, ".csproj")))
                {
                    newProjectFile = Path.ChangeExtension(projectFile, ".csproj");
                }
                else if (File.Exists(Path.ChangeExtension(projectFile, ".fsproj")))
                {
                    newProjectFile = Path.ChangeExtension(projectFile, ".fsproj");
                }
                else if (File.Exists(Path.ChangeExtension(projectFile, ".vbproj")))
                {
                    newProjectFile = Path.ChangeExtension(projectFile, ".vbproj");
                }
                else
                {
                    monitor.ReportError(GettextCatalog.GetString("Migrated project file not found."));
                    return(false);
                }
                var newProject = await project.ParentFolder.AddItem(monitor, newProjectFile);

                project.ParentFolder.Items.Remove(project);
                await newProject.ParentSolution.SaveAsync(monitor);

                RestorePackagesInProjectHandler.Run((DotNetProject)newProject);
            }
            else
            {
                solution.NeedsReload = true;
                FileService.NotifyFileChanged(solution.FileName);
            }
            return(true);
        }
 void OnDotNetCoreProjectReloaded(ProjectReloadedEventArgs e)
 {
     DotNetCoreProjectBuilderMaintainer.OnProjectReload(e);
     RestorePackagesInProjectHandler.Run(e.NewProject.DotNetProject, restoreTransitiveProjectReferences: true);
 }