Ejemplo n.º 1
0
        public string GetRelativePathToProjectFile(RepositoryContext context)
        {
            if (_probedForProjectFile)
            {
                return(_projectFileRelativePath);
            }

            var    sourceRepo  = context.SourceRepo;
            string projectFile = null;

            // Check if any of the sub-directories has a .csproj or .fsproj file and if that file has references
            // to websdk or azure functions

            // Since enumerating all files in the directory may take some time, write a message using the
            // given IStandardOutputWriter to alert the user of what is happening.
            _writer.WriteLine(string.Format(Labels.DotNetCoreEnumeratingFilesInRepo, DotNetCoreConstants.CSharpProjectFileExtension));

            // search for .csproj files
            var projectFiles = GetAllProjectFilesInRepo(
                sourceRepo,
                DotNetCoreConstants.CSharpProjectFileExtension);

            if (!projectFiles.Any())
            {
                _logger.LogDebug(
                    "Could not find any files with extension " +
                    $"'{DotNetCoreConstants.CSharpProjectFileExtension}' in repo.");

                // search for .fsproj files
                projectFiles = GetAllProjectFilesInRepo(
                    sourceRepo,
                    DotNetCoreConstants.FSharpProjectFileExtension);

                if (!projectFiles.Any())
                {
                    _logger.LogDebug(
                        "Could not find any files with extension " +
                        $"'{DotNetCoreConstants.FSharpProjectFileExtension}' in repo.");
                    return(null);
                }
            }

            var webAppProjects         = new List <string>();
            var azureFunctionsProjects = new List <string>();
            var allProjects            = new List <string>();

            foreach (var file in projectFiles)
            {
                allProjects.Add(file);
                if (ProjectFileHelpers.IsAspNetCoreWebApplicationProject(sourceRepo, file))
                {
                    webAppProjects.Add(file);
                }
                else if (ProjectFileHelpers.IsAzureFunctionsProject(sourceRepo, file))
                {
                    azureFunctionsProjects.Add(file);
                }
            }

            projectFile = GetProject(webAppProjects);
            if (projectFile == null)
            {
                projectFile = GetProject(azureFunctionsProjects);
            }

            if (projectFile == null)
            {
                _logger.LogDebug("Could not find a .NET Core project file to build.");
                return(null);
            }

            // Cache the results
            _probedForProjectFile    = true;
            _projectFileRelativePath = ProjectFileHelpers.GetRelativePathToRoot(projectFile, sourceRepo.RootPath);
            return(_projectFileRelativePath);
        }
Ejemplo n.º 2
0
        public string GetRelativePathToProjectFile(BuildScriptGeneratorContext context)
        {
            if (_probedForProjectFile)
            {
                return(_projectFileRelativePath);
            }

            var    sourceRepo  = context.SourceRepo;
            string projectFile = null;

            // Check if any of the sub-directories has a .csproj or .fsproj file and if that file has references
            // to websdk or azure functions

            // search for .csproj files
            var projectFiles = GetAllProjectFilesInRepo(
                sourceRepo,
                DotNetCoreConstants.CSharpProjectFileExtension);

            if (!projectFiles.Any())
            {
                _logger.LogDebug(
                    "Could not find any files with extension " +
                    $"'{DotNetCoreConstants.CSharpProjectFileExtension}' in repo.");

                // search for .fsproj files
                projectFiles = GetAllProjectFilesInRepo(
                    sourceRepo,
                    DotNetCoreConstants.FSharpProjectFileExtension);

                if (!projectFiles.Any())
                {
                    _logger.LogDebug(
                        "Could not find any files with extension " +
                        $"'{DotNetCoreConstants.FSharpProjectFileExtension}' in repo.");
                    return(null);
                }
            }

            var webAppProjects         = new List <string>();
            var azureFunctionsProjects = new List <string>();
            var allProjects            = new List <string>();

            foreach (var file in projectFiles)
            {
                allProjects.Add(file);
                if (ProjectFileHelpers.IsAspNetCoreWebApplicationProject(sourceRepo, file))
                {
                    webAppProjects.Add(file);
                }
                else if (ProjectFileHelpers.IsAzureFunctionsProject(sourceRepo, file))
                {
                    azureFunctionsProjects.Add(file);
                }
            }

            projectFile = GetProject(webAppProjects);
            if (projectFile == null)
            {
                projectFile = GetProject(azureFunctionsProjects);
            }

            if (projectFile == null)
            {
                _logger.LogDebug(
                    $"Could not find a project file to build. Available project files: " +
                    $"{string.Join(',', allProjects)}");
                return(null);
            }

            // Cache the results
            _probedForProjectFile    = true;
            _projectFileRelativePath = ProjectFileHelpers.GetRelativePathToRoot(projectFile, sourceRepo.RootPath);
            return(_projectFileRelativePath);
        }