Пример #1
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.IsDotNetCore5(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.IsDotNetCore5(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.IsDotNetCore5(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));
        }
Пример #2
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))
            {
                var targetFramework = VsHelper.GetTargetFramework(targetPath);
                if (!VsHelper.IsDotNetCore3(targetFramework))
                {
                    targetFramework = string.Empty;
                }

                return(new AspNetCoreBuilder(_environment,
                                             perDeploymentSettings,
                                             _propertyProvider,
                                             repositoryRoot,
                                             projectJson,
                                             null,
                                             targetFramework));
            }

            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));
        }