示例#1
0
        public static SolutionName GetSolutionName(SolutionFilePath solutionFilePath)
        {
            var solutionFileName = PathUtilities.GetFileName(solutionFilePath).AsSolutionFileName();

            var projectName = Utilities.GetSolutionName(solutionFileName);

            return(projectName);
        }
        public static void RemoveProjectFileFromSolutionFile(SolutionFilePath solutionFilePath, ProjectFilePath projectFilePath, ILogger logger)
        {
            logger.LogDebug($"Removing project file from solution file.\nSolution: {solutionFilePath}\nProject: {projectFilePath}");

            var arguments = $@"sln ""{solutionFilePath}"" remove ""{projectFilePath}""";

            ProcessRunner.Run(DotnetCommand.Value, arguments);

            logger.LogInformation($"Removed project file from solution file.\nSolution: {solutionFilePath}\nProject: {projectFilePath}");
        }
        public static void AddProjectFileToSolutionFile(SolutionFilePath solutionFilePath, ProjectFilePath projectFilePath, ILogger logger)
        {
            logger.LogDebug($"Adding project file to solution file.\nSolution: {solutionFilePath}\nProject: {projectFilePath}");

            var arguments = $@"sln ""{solutionFilePath}"" add ""{projectFilePath}""";

            ProcessRunner.Run(DotnetCommand.Value, arguments);

            logger.LogInformation($"Added project file to solution file.\nSolution: {solutionFilePath}\nProject: {projectFilePath}");
        }
        /// <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}");
            }
        }
示例#5
0
        private string GetSettingsJson()
        {
            Settings settings = new Settings
            {
                ProjectFilePath = ProjectFilePath,
                Properties      = GetMsBuildProperties(),
                ScriptFilePaths = ScriptFiles
                                  .Select(x => x.GetMetadata("FullPath"))
                                  .Where(x => !string.IsNullOrEmpty(x))
                                  .Distinct()
                                  .ToList(),
                SolutionFilePath = SolutionFilePath?.Contains("*Undefined*") == true ? null : SolutionFilePath
            };

            return(JsonConvert.SerializeObject(settings));
        }
        public static ProjectFilePath[] GetSolutionReferencedProjectFilePaths(SolutionFilePath solutionFilePath)
        {
            // Get all project file paths that are referenced by the solution file path.
            var arguments = $@"sln ""{solutionFilePath}"" list";

            var projectFilePaths = new List <ProjectFilePath>();

            var runOptions = new ProcessRunOptions
            {
                Command           = DotnetCommand.Value,
                Arguments         = arguments,
                ReceiveOutputData = (sender, e) => DotnetCommandServicesProvider.ProcessListSolutionProjectReferencesOutput(sender, e, solutionFilePath, projectFilePaths),
            };

            ProcessRunner.Run(runOptions);

            return(projectFilePaths.ToArray());
        }
        private static void ProcessListSolutionProjectReferencesOutput(object sender, DataReceivedEventArgs e, SolutionFilePath solutionFilePath, List <ProjectFilePath> projectFilePaths)
        {
            var dataString = e.Data ?? String.Empty;

            using (var reader = new StringReader(dataString))
            {
                while (!reader.ReadLineIsEnd(out string line))
                {
                    if (String.IsNullOrWhiteSpace(line) || line == "Project(s)" || line == "----------")
                    {
                        continue;
                    }

                    var projectFileRelativePath = new FileRelativePath(line);
                    var projectFilePath         = PathUtilitiesExtra.GetFilePath(solutionFilePath, projectFileRelativePath).AsProjectFilePath();

                    projectFilePaths.Add(projectFilePath);
                }
            }
        }
 /// <summary>
 /// Uses the <see cref="DotnetNewConventions.Instance"/>.
 /// </summary>
 public static void CreateSolutionFile(SolutionFilePath solutionFilePath, ILogger logger)
 {
     DotnetCommandServicesProvider.CreateSolutionFile(solutionFilePath, DotnetNewConventions.Instance, logger);
 }
示例#9
0
        public ValidateResult Validate(ValidateOptions options = null, bool throwException = true)
        {
            options = options ?? ValidateOptions.Default;

            AggregateException exception = null;

            if (options.SolutonFileMustExistInRoot && (!FileSystem.Exist(SolutionFilePath) || SolutionFilePath.IsSolution()))
            {
                exception = new AggregateException("Validate failed. Check InnerExceptions for details", new CakeException("A valid solution file must exist in the working directory!"));
            }

            if (exception != null && throwException)
            {
                throw exception;
            }

            return(new ValidateResult(exception == null, exception));
        }
        public static SolutionFilePath AsSolutionFilePath(this string value)
        {
            var solutionFilePath = new SolutionFilePath(value);

            return(solutionFilePath);
        }
示例#11
0
 public void CreateSolutionFile(SolutionFilePath solutionFilePath)
 {
     DotnetCommandServicesProvider.CreateSolutionFile(solutionFilePath, this.Logger);
 }
示例#12
0
 public void RemoveProject(SolutionFilePath solutionFilePath, ProjectFilePath projectFilePath)
 {
     DotnetCommandServicesProvider.RemoveProjectFileFromSolutionFile(solutionFilePath, projectFilePath, this.Logger);
 }
示例#13
0
 public void AddProject(SolutionFilePath solutionFilePath, ProjectFilePath projectFilePath)
 {
     DotnetCommandServicesProvider.AddProjectFileToSolutionFile(solutionFilePath, projectFilePath, this.Logger);
 }