Example #1
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IFileFinder fileFinder)
        {
            string repositoryRoot = _environment.RepositoryPath;

            // If there's a custom deployment file then let that take over.
            var command = settings.GetValue(SettingsKeys.Command);

            if (!String.IsNullOrEmpty(command))
            {
                return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = settings.GetValue(SettingsKeys.Project);

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Specific project was specified: " + targetProjectPath);

                targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\')));

                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      settings,
                                      fileFinder,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      settings,
                                      fileFinder,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite).FirstOrDefault();

            if (project == null)
            {
                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            return(new WebSiteBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
        }
Example #2
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IRepository repository)
        {
            string repositoryRoot = repository.RepositoryPath;

            // Use the cached vs projects file finder for: a. better performance, b. ignoring solutions/projects under node_modules
            var fileFinder = new CachedVsProjectsFileFinder(repository);

            // If there's a custom deployment file then let that take over.
            var command = settings.GetValue(SettingsKeys.Command);

            if (!String.IsNullOrEmpty(command))
            {
                return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command));
            }

            // If the user provided specific generator arguments, that overrides any detection logic
            string scriptGeneratorArgs = settings.GetValue(SettingsKeys.ScriptGeneratorArgs);

            if (!String.IsNullOrEmpty(scriptGeneratorArgs))
            {
                return(new CustomGeneratorCommandSiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, scriptGeneratorArgs));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = settings.GetValue(SettingsKeys.Project);

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Specific project was specified: " + targetProjectPath);
                targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\')));
            }

            if (settings.RunFromLocalZip())
            {
                return(new RunFromZipSiteBuilder());
            }

            if (!settings.DoBuildDuringDeployment())
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new BasicBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath));
            }

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      settings,
                                      fileFinder,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      settings,
                                      fileFinder,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            // shunTODO need to implement this
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault();

            if (project == null)
            {
                // Try executable type project
                project = solution.Projects.Where(p => p.IsExecutable).FirstOrDefault();
                if (project != null)
                {
                    return(new DotNetConsoleBuilder(_environment,
                                                    settings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    project.AbsolutePath,
                                                    solution.Path));
                }

                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                // we have a solution file, but no deployable project
                // shunTODO how often do we run into this
                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            if (project.IsAspNetCore)
            {
                return(new AspNetCoreBuilder(_environment,
                                             settings,
                                             _propertyProvider,
                                             repositoryRoot,
                                             project.AbsolutePath,
                                             solution.Path));
            }

            if (project.IsWebSite)
            {
                return(new WebSiteBuilder(_environment,
                                          settings,
                                          _propertyProvider,
                                          repositoryRoot,
                                          project.AbsolutePath,
                                          solution.Path));
            }

            return(new FunctionMsbuildBuilder(_environment,
                                              settings,
                                              _propertyProvider,
                                              repositoryRoot,
                                              project.AbsolutePath,
                                              solution.Path));
        }
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IRepository repository, DeploymentInfoBase deploymentInfo)
        {
            string repositoryRoot = repository.RepositoryPath;

            // Use the cached vs projects file finder for: a. better performance, b. ignoring solutions/projects under node_modules
            var fileFinder = new CachedVsProjectsFileFinder(repository);

            // If there's a custom deployment file then let that take over.
            var command = settings.GetValue(SettingsKeys.Command);

            if (!String.IsNullOrEmpty(command))
            {
                return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command));
            }

            // If the user provided specific generator arguments, that overrides any detection logic
            string scriptGeneratorArgs = settings.GetValue(SettingsKeys.ScriptGeneratorArgs);

            if (!String.IsNullOrEmpty(scriptGeneratorArgs))
            {
                return(new CustomGeneratorCommandSiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, scriptGeneratorArgs));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = settings.GetValue(SettingsKeys.Project);

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Specific project was specified: " + targetProjectPath);
                targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\')));
            }

            if (deploymentInfo != null && deploymentInfo.Deployer == Constants.OneDeploy)
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new OneDeployBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath, deploymentInfo));
            }

            if (settings.RunFromLocalZip())
            {
                return(new RunFromZipSiteBuilder());
            }

            if (!settings.DoBuildDuringDeployment())
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                if (DeploymentHelper.IsDeploymentV2Request())
                {
                    return(new DeploymentV2Builder(_environment, settings, _propertyProvider, repositoryRoot));
                }
                else
                {
                    return(new BasicBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath));
                }
            }

            // Check if we really need a builder for this
            // If not, return the NoOpBuilder
            string appFramework = System.Environment.GetEnvironmentVariable("FRAMEWORK");

            if (!string.IsNullOrEmpty(appFramework) && string.Equals(appFramework, "STATICSITE", StringComparison.OrdinalIgnoreCase))
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new NoOpBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath));
            }

            // If ENABLE_ORYX_BUILD is not set, for function app, we assume it on by default
            string enableOryxBuild = System.Environment.GetEnvironmentVariable("ENABLE_ORYX_BUILD");

            if (!string.IsNullOrEmpty(enableOryxBuild))
            {
                if (StringUtils.IsTrueLike(enableOryxBuild))
                {
                    return(new OryxBuilder(_environment, settings, _propertyProvider, repositoryRoot));
                }
            }
            else if (FunctionAppHelper.LooksLikeFunctionApp())
            {
                return(new OryxBuilder(_environment, settings, _propertyProvider, repositoryRoot));
            }

            string framework = System.Environment.GetEnvironmentVariable("FRAMEWORK");

            if (framework.Equals("ruby", StringComparison.OrdinalIgnoreCase))
            {
                return(new RubySiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, targetProjectPath));
            }

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      settings,
                                      fileFinder,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      settings,
                                      fileFinder,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            // shunTODO need to implement this
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault();

            if (project == null)
            {
                // Try executable type project
                project = solution.Projects.Where(p => p.IsExecutable).FirstOrDefault();
                if (project != null)
                {
                    return(new DotNetConsoleBuilder(_environment,
                                                    settings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    project.AbsolutePath,
                                                    solution.Path));
                }

                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                // we have a solution file, but no deployable project
                // shunTODO how often do we run into this
                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            if (project.IsAspNetCore)
            {
                return(new AspNetCoreBuilder(_environment,
                                             settings,
                                             _propertyProvider,
                                             repositoryRoot,
                                             project.AbsolutePath,
                                             solution.Path));
            }

            if (project.IsWebSite)
            {
                return(new WebSiteBuilder(_environment,
                                          settings,
                                          _propertyProvider,
                                          repositoryRoot,
                                          project.AbsolutePath,
                                          solution.Path));
            }

            return(new FunctionMsbuildBuilder(_environment,
                                              settings,
                                              _propertyProvider,
                                              repositoryRoot,
                                              project.AbsolutePath,
                                              solution.Path));
        }
Example #4
0
        private ISiteBuilder DetermineProjectFromSolution(ILogger logger, IDeploymentSettingsManager settings, IRepository repository, VsSolution solution)
        {
            string repositoryRoot = repository.RepositoryPath;

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            // shunTODO need to implement this
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault();

            if (project == null)
            {
                // Try executable type project
                project = solution.Projects.Where(p => p.IsExecutable).FirstOrDefault();
                if (project != null)
                {
                    if (VsHelper.UseMSBuild1607() || VsHelper.IsDotNetCore5(project.TargetFramework))
                    {
                        return(new DotNetConsoleMSBuild1607Builder(_environment,
                                                                   settings,
                                                                   _propertyProvider,
                                                                   repositoryRoot,
                                                                   project.AbsolutePath,
                                                                   solution.Path));
                    }
                    else if (VsHelper.UseMSBuild16())
                    {
                        return(new DotNetCoreConsoleMSBuild16Builder(_environment,
                                                                     settings,
                                                                     _propertyProvider,
                                                                     repositoryRoot,
                                                                     project.AbsolutePath,
                                                                     solution.Path));
                    }
                    else
                    {
                        return(new DotNetConsoleBuilder(_environment,
                                                        settings,
                                                        _propertyProvider,
                                                        repositoryRoot,
                                                        project.AbsolutePath,
                                                        solution.Path));
                    }
                }

                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                // we have a solution file, but no deployable project
                // shunTODO how often do we run into this
                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            if (project.IsAspNetCore)
            {
                if (VsHelper.UseMSBuild1607() || VsHelper.IsDotNetCore5(project.TargetFramework))
                {
                    return(new AspNetCoreMSBuild1607Builder(_environment,
                                                            settings,
                                                            _propertyProvider,
                                                            repositoryRoot,
                                                            project.AbsolutePath,
                                                            solution.Path));
                }
                else if (VsHelper.UseMSBuild16())
                {
                    return(new AspNetCoreMSBuild16Builder(_environment,
                                                          settings,
                                                          _propertyProvider,
                                                          repositoryRoot,
                                                          project.AbsolutePath,
                                                          solution.Path));
                }
                else
                {
                    return(new AspNetCoreBuilder(_environment,
                                                 settings,
                                                 _propertyProvider,
                                                 repositoryRoot,
                                                 project.AbsolutePath,
                                                 solution.Path));
                }
            }


            if (project.IsWebSite)
            {
                return(new WebSiteBuilder(_environment,
                                          settings,
                                          _propertyProvider,
                                          repositoryRoot,
                                          project.AbsolutePath,
                                          solution.Path));
            }

            if (VsHelper.UseMSBuild1607() || VsHelper.IsDotNetCore5(project.TargetFramework))
            {
                return(new FunctionMSBuild1607Builder(_environment,
                                                      settings,
                                                      _propertyProvider,
                                                      repositoryRoot,
                                                      project.AbsolutePath,
                                                      solution.Path));
            }
            else if (VsHelper.UseMSBuild16())
            {
                return(new FunctionMSBuild16Builder(_environment,
                                                    settings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    project.AbsolutePath,
                                                    solution.Path));
            }
            else
            {
                return(new FunctionMsbuildBuilder(_environment,
                                                  settings,
                                                  _propertyProvider,
                                                  repositoryRoot,
                                                  project.AbsolutePath,
                                                  solution.Path));
            }
        }
Example #5
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger)
        {
            string repositoryRoot = _environment.RepositoryPath;
            var    configuration  = new DeploymentConfiguration(repositoryRoot);

            // If there's a custom deployment file then let that take over.
            if (!String.IsNullOrEmpty(configuration.Command))
            {
                return(new CustomBuilder(repositoryRoot, _environment.TempPath, configuration.Command, _propertyProvider, _environment.SiteRootPath));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = configuration.ProjectPath;

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Found .deployment file in repository");

                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite).FirstOrDefault();

            if (project == null)
            {
                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                return(new BasicBuilder(repositoryRoot, _environment.TempPath, _environment.ScriptPath, _environment.SiteRootPath));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      _environment.TempPath,
                                      _environment.NuGetCachePath,
                                      solution.Path));
            }

            return(new WebSiteBuilder(_propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      _environment.TempPath,
                                      _environment.NuGetCachePath,
                                      solution.Path));
        }