Exemplo n.º 1
0
        private ISiteBuilder ResolveProject(string repositoryRoot, string targetPath, IDeploymentSettingsManager perDeploymentSettings, IFileFinder fileFinder, bool tryWebSiteProject, SearchOption searchOption = SearchOption.AllDirectories, bool specificConfiguration = true)
        {
            if (DeploymentHelper.IsProject(targetPath))
            {
                return(DetermineProject(repositoryRoot, targetPath, perDeploymentSettings, fileFinder));
            }

            // Check for loose projects
            var projects = DeploymentHelper.GetProjects(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));
            }

            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(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));
        }
Exemplo n.º 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))
            {
                string targetFramework = VsHelper.GetTargetFrameworkJson(projectJson);
                if (VsHelper.UseMSBuild1607() || VsHelper.IsDotNetCore5(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));
        }