public static void Pack(FilePath dotnetExecutableFilePath, ProjectFilePath projectFilePath, NupkgFilePath nupkgFilePath, ILogger logger)
        {
            var packageDirectoryPath = PathUtilities.GetDirectoryPath(nupkgFilePath);

            // Use the pack command to get the package file-path created by dotnet.
            var defaultPackageFilePath = DotnetCommandServicesProvider.Pack(dotnetExecutableFilePath, projectFilePath, packageDirectoryPath, logger);

            // If the package file-path created by dotnet is not the same as the specified package file-path, copy the file to the new path.
            if (nupkgFilePath.Value != defaultPackageFilePath.Value)
            {
                File.Copy(defaultPackageFilePath.Value, nupkgFilePath.Value, true);
                File.Delete(defaultPackageFilePath.Value);
            }
        }
        public static void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath, DotnetNewConventions conventions, ILogger logger)
        {
            var projectDirectoryPath            = PathUtilities.GetDirectoryPath(projectFilePath).AsProjectDirectoryPath();
            var projectFileName                 = PathUtilities.GetFileName(projectFilePath).AsProjectFileName();
            var projectFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(projectFileName);
            var projectName = conventions.ProjectNameFromProjectFileNameWithoutExtension(projectFileNameWithoutExtension);

            var createdProjectFilePath = DotnetCommandServicesProvider.CreateProjectFile(projectType, projectName, projectDirectoryPath, logger);

            // Throw an exception if the solution file-path created by dotnet new is not the one we were expecting.
            if (createdProjectFilePath.Value != projectFilePath.Value)
            {
                throw new Exception($"Project creation file path mismatch.\nExpected: {projectFilePath}\nCreated: {createdProjectFilePath}");
            }
        }
        /// <summary>
        /// Creates a solution file at the specified file-path.
        /// </summary>
        /// <remarks>
        /// This method feeds the solution directory-path and solution-name value required to have the dotnet new command create a solution-file at the specified path.
        /// </remarks>
        public static void CreateSolutionFile(SolutionFilePath solutionFilePath, DotnetNewConventions conventions, ILogger logger)
        {
            var solutionDirectoryPath            = PathUtilities.GetDirectoryPath(solutionFilePath).AsSolutionDirectoryPath();
            var solutionFileName                 = PathUtilities.GetFileName(solutionFilePath).AsSolutionFileName();
            var solutionFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(solutionFileName);
            var solutionName = conventions.SolutionNameFromSolutionFileNameWithoutExtension(solutionFileNameWithoutExtension);

            var createdSolutionFilePath = DotnetCommandServicesProvider.CreateSolutionFile(solutionDirectoryPath, solutionName, logger);

            // Throw an exception if the solution file-path created by dotnet new is not the one we were expecting.
            if (createdSolutionFilePath.Value != solutionFilePath.Value)
            {
                throw new Exception($"Solution creation file path mismatch.\nExpected: {solutionFilePath}\nCreated: {createdSolutionFilePath}");
            }
        }
        private static void ProcessListProjectProjectReferencesOutput(object sender, DataReceivedEventArgs e, ProjectFilePath projectFilePath, List <ProjectFilePath> projectFilePaths)
        {
            var projectDirectoryPath = PathUtilities.GetDirectoryPath(projectFilePath);

            var dataString = e.Data ?? String.Empty;

            using (var reader = new StringReader(dataString))
            {
                while (!reader.ReadLineIsEnd(out string line))
                {
                    if (String.IsNullOrWhiteSpace(line) || line == "Project reference(s)" || line == "--------------------" || line.BeginsWith("There are no Project to Project references in project"))
                    {
                        continue;
                    }

                    var referencedProjectFileRelativePath = new FileRelativePath(line);
                    // Project file relative paths are relative to the project directory path.
                    var referenedProjectFilePath = PathUtilitiesExtra.GetFilePath(projectDirectoryPath, referencedProjectFileRelativePath).AsProjectFilePath();

                    projectFilePaths.Add(referenedProjectFilePath);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// The directory containing the solution-file is the solution-directory.
        /// </summary>
        public static SolutionDirectoryPath GetSolutionDirectoryPath(SolutionFilePath solutionFilePath)
        {
            var solutionDirectoryPath = PathUtilities.GetDirectoryPath(solutionFilePath).AsSolutionDirectoryPath();

            return(solutionDirectoryPath);
        }
예제 #6
0
        /// <summary>
        /// The directory containing the project-file is the project-directory.
        /// </summary>
        public static ProjectDirectoryPath GetProjectDirectoryPath(ProjectFilePath projectFilePath)
        {
            var projectDirectoryPath = PathUtilities.GetDirectoryPath(projectFilePath).AsProjectDirectoryPath();

            return(projectDirectoryPath);
        }