示例#1
0
        public static async Task InstallTargets(EnvDTE.Project envDteProject, IProjectLockService projectLockService, UnconfiguredProject unconfiguredProject, string toolsPath)
        {
            var logger = new TraceLogger();

            try
            {
                if (projectLockService == null)
                {
                    throw new ArgumentNullException("projectLockService");
                }

                if (unconfiguredProject == null)
                {
                    throw new ArgumentNullException("unconfiguredProject");
                }

                using (var access = await projectLockService.WriteLockAsync())
                {
                    var configuredProject = await unconfiguredProject.GetSuggestedConfiguredProjectAsync();

                    Project project = await access.GetProjectAsync(configuredProject);

                    // If you're going to change the project in any way,
                    // check it out from SCC first:
                    await access.CheckoutAsync(configuredProject.UnconfiguredProject.FullPath);

                    // install targets

                    var installer = new InstallTargetsHelper(logger);
                    installer.Install(project, toolsPath);
                    // configureCallback(project);

                    IProjectTreeService projectTreeService = configuredProject.Services.ExportProvider.GetExportedValue <IProjectTreeService>();
                    await projectTreeService.PublishLatestTreeAsync();

                    // envDteProject.Save(envDteProject.FullName);

                    // save changes.
                    //project.Save(project.FullPath);
                }
            }
            catch (AggregateException ex)
            {
                logger.LogError(ex.Message);
                foreach (var e in ex.InnerExceptions)
                {
                    logger.LogError(e.Message);
                }

                throw;
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
            }
        }
示例#2
0
        public void VisitInstallTargetsCommand(InstallTargetsToVSProjectFileOptions options)
        {
            _Logger.LogInfo(string.Format("Installing targets to: {0}", options.ProjectName));

            Microsoft.Build.Evaluation.ProjectCollection collection = new Microsoft.Build.Evaluation.ProjectCollection();
            Microsoft.Build.Evaluation.Project           project    = new Microsoft.Build.Evaluation.Project(options.ProjectName, null, null, collection, Microsoft.Build.Evaluation.ProjectLoadSettings.IgnoreMissingImports);

            var installHelper = new InstallTargetsHelper(_Logger);
            var toolsDir      = options.ToolsPath.TrimEnd(new char[] { '\\', '/' });

            this.Success = installHelper.Install(project, toolsDir);
        }