Example #1
0
        // unless user specifies which project to deploy, targetPath == repositoryRoot
        private ISiteBuilder ResolveProject(string repositoryRoot, string targetPath, IDeploymentSettingsManager perDeploymentSettings, IFileFinder fileFinder, bool tryWebSiteProject, SearchOption searchOption = SearchOption.AllDirectories, bool specificConfiguration = true)
        {
            if (DeploymentHelper.IsMsBuildProject(targetPath))
            {
                // needs to check for project file existence
                if (!File.Exists(targetPath))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Error_ProjectDoesNotExist,
                                                                      targetPath));
                }
                return(DetermineProject(repositoryRoot, targetPath, perDeploymentSettings, fileFinder));
            }

            // Check for loose projects
            var projects = DeploymentHelper.GetMsBuildProjects(targetPath, fileFinder, searchOption);

            if (projects.Count > 1)
            {
                // Can't determine which project to build
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  Resources.Error_AmbiguousProjects,
                                                                  String.Join(", ", projects)));
            }
            else if (projects.Count == 1)
            {
                return(DetermineProject(repositoryRoot, projects[0], perDeploymentSettings, fileFinder));
            }

            // Check for ASP.NET Core project without VS solution or project
            // for ASP.NET Core project which only has project.json, but not xproj ie: dotnet preview2 cli project
            string projectJson;

            if (AspNetCoreHelper.TryAspNetCoreWebProject(targetPath, fileFinder, out projectJson))
            {
                string targetFramework = VsHelper.GetTargetFrameworkJson(projectJson);
                if (VsHelper.UseMSBuild1607() || VsHelper.IsNewDotNetCoreMajorVersion(targetFramework))
                {
                    return(new AspNetCoreMSBuild1607Builder(_environment,
                                                            perDeploymentSettings,
                                                            _propertyProvider,
                                                            repositoryRoot,
                                                            projectJson,
                                                            null));
                }
                else if (VsHelper.UseMSBuild16())
                {
                    return(new AspNetCoreMSBuild16Builder(_environment,
                                                          perDeploymentSettings,
                                                          _propertyProvider,
                                                          repositoryRoot,
                                                          projectJson,
                                                          null));
                }
                else
                {
                    return(new AspNetCoreBuilder(_environment,
                                                 perDeploymentSettings,
                                                 _propertyProvider,
                                                 repositoryRoot,
                                                 projectJson,
                                                 null));
                }
            }

            if (tryWebSiteProject)
            {
                // Website projects need a solution to build so look for one in the repository path
                // that has this website in it.
                var solutions = VsHelper.FindContainingSolutions(repositoryRoot, targetPath, fileFinder);

                // More than one solution is ambiguous
                if (solutions.Count > 1)
                {
                    ThrowAmbiguousSolutionsError(solutions);
                }
                else if (solutions.Count == 1)
                {
                    // Unambiguously pick the root
                    return(new WebSiteBuilder(_environment,
                                              perDeploymentSettings,
                                              _propertyProvider,
                                              repositoryRoot,
                                              targetPath,
                                              solutions[0].Path));
                }
            }

            // This should only ever happen if the user specifies an invalid directory.
            // The other case where the method is called we always resolve the path so it's a non issue there.
            if (specificConfiguration && !Directory.Exists(targetPath))
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  Resources.Error_ProjectDoesNotExist,
                                                                  targetPath));
            }

            // If there's none then use the basic builder (the site is xcopy deployable)
            return(ResolveNonAspProject(repositoryRoot, targetPath, perDeploymentSettings));
        }
Example #2
0
        // used when we have a project file
        private ISiteBuilder DetermineProject(string repositoryRoot, string targetPath, IDeploymentSettingsManager perDeploymentSettings, IFileFinder fileFinder)
        {
            var    solution         = VsHelper.FindContainingSolution(repositoryRoot, targetPath, fileFinder);
            string solutionPath     = solution?.Path;
            var    projectTypeGuids = VsHelper.GetProjectTypeGuids(targetPath);
            var    targetFramework  = VsHelper.GetTargetFramework(targetPath);

            if (VsHelper.IsWap(projectTypeGuids))
            {
                return(new WapBuilder(_environment,
                                      perDeploymentSettings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      targetPath,
                                      solutionPath));
            }
            else if (AspNetCoreHelper.IsDotnetCoreFromProjectFile(targetPath, projectTypeGuids))
            {
                if (VsHelper.UseMSBuild1607() || VsHelper.IsNewDotNetCoreMajorVersion(targetFramework))
                {
                    return(new AspNetCoreMSBuild1607Builder(_environment,
                                                            perDeploymentSettings,
                                                            _propertyProvider,
                                                            repositoryRoot,
                                                            targetPath,
                                                            solutionPath));
                }
                else if (VsHelper.UseMSBuild16())
                {
                    return(new AspNetCoreMSBuild16Builder(_environment,
                                                          perDeploymentSettings,
                                                          _propertyProvider,
                                                          repositoryRoot,
                                                          targetPath,
                                                          solutionPath));
                }
                else
                {
                    return(new AspNetCoreBuilder(_environment,
                                                 perDeploymentSettings,
                                                 _propertyProvider,
                                                 repositoryRoot,
                                                 targetPath,
                                                 solutionPath));
                }
            }
            else if (VsHelper.IsExecutableProject(targetPath))
            {
                if (VsHelper.UseMSBuild1607() || VsHelper.IsNewDotNetCoreMajorVersion(targetFramework))
                {
                    return(new DotNetConsoleMSBuild1607Builder(_environment,
                                                               perDeploymentSettings,
                                                               _propertyProvider,
                                                               repositoryRoot,
                                                               targetPath,
                                                               solutionPath));
                }
                else if (VsHelper.UseMSBuild16())
                {
                    return(new DotNetCoreConsoleMSBuild16Builder(_environment,
                                                                 perDeploymentSettings,
                                                                 _propertyProvider,
                                                                 repositoryRoot,
                                                                 targetPath,
                                                                 solutionPath));
                }
                else
                {
                    // This is a console app
                    return(new DotNetConsoleBuilder(_environment,
                                                    perDeploymentSettings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    targetPath,
                                                    solutionPath));
                }
            }
            else if (FunctionAppHelper.LooksLikeFunctionApp())
            {
                if (FunctionAppHelper.IsCSharpFunctionFromProjectFile(targetPath))
                {
                    if (VsHelper.UseMSBuild1607() || VsHelper.IsNewDotNetCoreMajorVersion(targetFramework))
                    {
                        return(new FunctionMSBuild1607Builder(_environment,
                                                              perDeploymentSettings,
                                                              _propertyProvider,
                                                              repositoryRoot,
                                                              targetPath,
                                                              solutionPath));
                    }
                    else if (VsHelper.UseMSBuild16())
                    {
                        return(new FunctionMSBuild16Builder(_environment,
                                                            perDeploymentSettings,
                                                            _propertyProvider,
                                                            repositoryRoot,
                                                            targetPath,
                                                            solutionPath));
                    }
                    else
                    {
                        return(new FunctionMsbuildBuilder(_environment,
                                                          perDeploymentSettings,
                                                          _propertyProvider,
                                                          repositoryRoot,
                                                          targetPath,
                                                          solutionPath));
                    }
                }
                else
                {
                    // csx or node function with extensions.csproj
                    return(new FunctionBasicBuilder(_environment,
                                                    perDeploymentSettings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    Path.GetDirectoryName(targetPath)));
                }
            }

            throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                              Resources.Error_ProjectNotDeployable,
                                                              targetPath));
        }
Example #3
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.IsNewDotNetCoreMajorVersion(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.IsNewDotNetCoreMajorVersion(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.IsNewDotNetCoreMajorVersion(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));
            }
        }