示例#1
0
        /// <summary>
        /// 第四步,编译所有代码
        /// </summary>
        private static void BuildProject(string sourcePath, int step = 4)
        {
            Cli.Warn($"{step}. 编译生成项目及还原所有 Nuget 包...");
            Cli.EmptyLine();

            var stdOutBuffer = new StringBuilder();
            var stdErrBuffer = new StringBuilder();

            var result = Cmd.Cli.Wrap("dotnet")
                         .WithArguments($"build {sourcePath}")
                         .WithStandardOutputPipe(Cmd.PipeTarget.ToStringBuilder(stdOutBuffer))
                         .WithStandardErrorPipe(Cmd.PipeTarget.ToStringBuilder(stdErrBuffer))
                         .ExecuteAsync().GetAwaiter().GetResult();

            var stdOut = stdOutBuffer.ToString();
            var stdErr = stdErrBuffer.ToString();

            // 如果编译失败
            if (!string.IsNullOrWhiteSpace(stdErr) || string.IsNullOrWhiteSpace(stdOut))
            {
                Cli.Error("编译失败:");
                Cli.Error(stdErr);
                Cli.Exit();
            }

            // 输出所有编译日志
            Cli.Success(stdOut);

            Cli.EmptyLine();
            Load();
        }
示例#2
0
        /// <summary>
        /// 第二步,扫描所有 .csproj 文件
        /// </summary>
        /// <param name="sourcePath"></param>
        /// <returns></returns>
        private static (string[], string[]) Step2(string sourcePath)
        {
            // 第二步,扫描所有 .csproj 文件
            Cli.Warn("2. 扫描指定目录所有项目文件...");
            Cli.EmptyLine();

            var files     = Directory.GetFiles(sourcePath, "*.csproj", SearchOption.AllDirectories);
            var fileNames = files.Select(u => Path.GetFileName(u)).ToArray();

            if (files.Length == 0)
            {
                Cli.Error($"这不是一个有效的解决方案目录 [{sourcePath}]");
                Cli.Exit();
            }

            // 输出所有项目文件
            foreach (var item in fileNames)
            {
                Cli.Success(" " + item);
            }

            Cli.EmptyLine();
            Load();
            return(files, fileNames);
        }
示例#3
0
        /// <summary>
        /// 第一步,检测 SDK
        /// </summary>
        private static void Step1()
        {
            Cli.Warn("1. 检查是否安装 .NET6 最新版 SDK...");
            Cli.EmptyLine();

            var stdOutBuffer = new StringBuilder();
            var stdErrBuffer = new StringBuilder();

            var result = Cmd.Cli.Wrap("dotnet")
                         .WithArguments("--list-sdks")
                         .WithStandardOutputPipe(Cmd.PipeTarget.ToStringBuilder(stdOutBuffer))
                         .WithStandardErrorPipe(Cmd.PipeTarget.ToStringBuilder(stdErrBuffer))
                         .ExecuteAsync().GetAwaiter().GetResult();

            var stdOut = stdOutBuffer.ToString();
            var stdErr = stdErrBuffer.ToString();

            // 判断是否安装 SDK
            if (!string.IsNullOrWhiteSpace(stdErr) || string.IsNullOrWhiteSpace(stdOut))
            {
                Cli.Error("未检测到安装任何 .NET SDK,程序终止!复制链接下载:https://dotnet.microsoft.com/download/dotnet/6.0");
                Cli.Exit();
            }

            // 判断是否安装了最新的 .NET 6
            var sdks = stdOut.Split('\n', StringSplitOptions.RemoveEmptyEntries);

            if (!sdks.Any(u => u.StartsWith(net6Version)))
            {
                Cli.Error($"未检测到安装 .NET 6 最新 SDK({net6Version}),程序终止!复制链接下载:https://dotnet.microsoft.com/download/dotnet/6.0");
                Cli.Exit();
            }

            // 输出所有安装的 SDK
            foreach (var item in sdks)
            {
                if (item.StartsWith(net6Version))
                {
                    Cli.Success(" " + item);
                }
                else
                {
                    Cli.WriteLine(" " + item);
                }
            }

            Cli.EmptyLine();
            Load();
        }
示例#4
0
 static void NoMatchesHandler(bool isEmpty, string[] operands, Dictionary <string, object> noMatches)
 {
     if (isEmpty)
     {
         Cli.WriteLine($"欢迎使用 {Cli.GetDescription()}");
     }
     if (operands.Length > 0)
     {
         Cli.Error($"未找到该操作符:{string.Join(",", operands)}");
     }
     if (noMatches.Count > 0)
     {
         Cli.Error($"未找到该参数:{string.Join(",", noMatches.Keys)}");
     }
 }