static void Main(string[] args) { var appConfigurator = AppConfigurator.GetAppConfigurator(); var appConfiguratorDefault = appConfigurator.Default; var(ownerCommand, runningCommand) = SubCommandParser.ParseCommandlineValue(args); if (runningCommand.Count == 0) { return; } // 其中的 OwnerCommand 先忽略 // 判断 runningCommand 是否存在需要转换的参数 var actualCommandline = CommandlineEngine.FillCommandline(runningCommand.ToArray(), appConfiguratorDefault); var commandlineArgString = new StringBuilder(); for (var i = 1; i < actualCommandline.Length; i++) { var arg = actualCommandline[i]; Console.WriteLine($"[{i}] = {arg}"); commandlineArgString.Append(ProcessCommand.ToArgumentPath(arg)); commandlineArgString.Append(' '); } var arguments = commandlineArgString.ToString(); Console.WriteLine($"Command = {actualCommandline[0]} {arguments}"); var(success, output) = ProcessCommand.ExecuteCommand(actualCommandline[0], arguments); Console.WriteLine(output); }
public CommonLogger() { var appConfigurator = AppConfigurator.GetAppConfigurator(); var logConfiguration = appConfigurator.Of <LogConfiguration>(); FileLog = FileLogProvider.GetFileLog(logConfiguration); }
static void Main(string[] args) { var nuGet = new NuGet(AppConfigurator.GetAppConfigurator()); nuGet.Restore(); // todo 支持更多命令 }
static void Main(string[] args) { var appConfigurator = AppConfigurator.GetAppConfigurator(); var nuGet = new NuGet(appConfigurator); Log.Info($"当前命令行 {Environment.CommandLine}"); if (args.Length == 1) { // 可以传入命令行或文件 if (Directory.Exists(args[0])) { Log.Info($"传入 NuGet 文件所在文件夹 {args[0]}"); appConfigurator.Of <CompileConfiguration>().NupkgDirectory = args[0]; nuGet.PublishNupkg(); } else if (File.Exists(args[0])) { Log.Info($"传入 NuGet 文件 {args[0]}"); nuGet.PublishNupkg(new FileInfo(args[0])); } else if (args[0] == "-h" || args[0] == "--help") { Console.WriteLine(@"此命令用于将 NuGet 包发布到配置的默认源,默认将会取 Compile.NupkgDirectory 文件夹内的 nupkg 文件上传到 Nuget.Source 服务器 命令可不填写参数,不填写时将会使用配置的 Compile.NupkgDirectory 文件夹内的所有 nupkg 文件上传 命令可选参数是 nupkg 文件路径或文件所在文件夹 NuGetPublishTask [nupkg file path | nupkg folder] NuGetPublishTask [nupkg 文件路径 | nupkg 文件所在文件夹] 如需指定非配置里面的 NuGet 服务器等,请直接使用 nuget 命令"); return; } else { Log.Error($"未能解析传入内容为 NuGet 文件或所在文件夹"); Environment.Exit(-1); return; } } else if (args.Length == 0) { nuGet.PublishNupkg(); } else { Log.Error("此命令仅接受传入当前 NuGet 包文件路径或所在文件夹,此命令用于将 NuGet 包发布到配置的默认源"); Environment.Exit(-1); return; } }
public static void FillGitInfo(IAppConfigurator appConfigurator = null) { appConfigurator ??= AppConfigurator.GetAppConfigurator(); var git = GitHelper.GetGitRepo(appConfigurator); var gitCommitRevisionCount = git.GetGitCommitRevisionCount(); var gitConfiguration = appConfigurator.Of <GitConfiguration>(); gitConfiguration.GitCount = gitCommitRevisionCount; gitConfiguration.CurrentCommit = git.GetCurrentCommit(); var compileConfiguration = appConfigurator.Of <CompileConfiguration>(); if (string.IsNullOrEmpty(compileConfiguration.CurrentCommit)) { compileConfiguration.CurrentCommit = gitConfiguration.CurrentCommit; } }
static void Main(string[] args) { SDK.Run(() => { // 这个命令可以提供给其他命令作为控制台输出使用,此时需要减少输出内容 Log.LogLevel = LogLevel.Error; var git = GitHelper.GetGitRepo(); var gitCommitRevisionCount = git.GetGitCommitRevisionCount(); Console.WriteLine(gitCommitRevisionCount); var appConfigurator = AppConfigurator.GetAppConfigurator(); var gitConfiguration = appConfigurator.Of <GitConfiguration>(); gitConfiguration.GitCount = gitCommitRevisionCount; gitConfiguration.CurrentCommit = git.GetCurrentCommit(); }).Wait(); }
static void Main(string[] args) { var appConfigurator = AppConfigurator.GetAppConfigurator(); var compileConfiguration = appConfigurator.Of <CompileConfiguration>(); // 用于替换的列表 var replaceDictionary = new Dictionary <string, string>() { { "$(AppVersion)", compileConfiguration.AppVersion } }; // 替换一些变量,然后原原本本传入到 dotnet 命令里面 var argsString = new StringBuilder(); foreach (var arg in args) { var temp = arg; if (replaceDictionary.TryGetValue(temp, out var replaceValue)) { temp = replaceValue; } temp = ProcessCommand.ToArgumentPath(temp); argsString.Append(temp); argsString.Append(' '); } Log.Info($"dotnet {argsString}"); var(success, output) = ProcessCommand.ExecuteCommand("dotnet", argsString.ToString()); if (success) { Log.Info(output); } else { Log.Error(output); } }
static void Main(string[] args) { Parser.Default.ParseArguments <AssemblyOption>(args).WithParsed(option => { var appConfigurator = AppConfigurator.GetAppConfigurator(); var compileConfiguration = appConfigurator.Of <CompileConfiguration>(); #if DEBUG var fileSniff = new FileSniff(appConfigurator); fileSniff.Sniff(); #endif var file = option.AssemblyInfoFile; if (string.IsNullOrEmpty(file)) { file = appConfigurator.Default["AssemblyInfoFile"]; } if (string.IsNullOrEmpty(file)) { throw new ArgumentException($"Can not find AssemblyInfoFile, try to input --AssemblyInfoFile value"); } if (!Path.IsPathRooted(file)) { var codeDirectory = compileConfiguration.CodeDirectory; file = Path.Combine(codeDirectory, file); file = Path.GetFullPath(file); } appConfigurator.Default["AssemblyInfoFile"] = file; Log.Info($"Start read assmebly info file {file}"); if (!File.Exists(file)) { throw new ArgumentException($"The assmebly info file {file} can not be found."); } var formatRegex = option.VersionFormatRegex; if (string.IsNullOrEmpty(formatRegex)) { formatRegex = "Version = \\\"(\\d+.\\d+.\\d+)\\\";"; } Log.Info($"VersionFormatRegex: {formatRegex}"); var content = File.ReadAllText(file); var match = Regex.Match(content, formatRegex); if (match.Success) { var assemblyVersion = match.Groups[1].Value; var fieldCount = GetVersionFieldCount(assemblyVersion); Log.Info($"assembly version: {assemblyVersion}"); appConfigurator.Default["AssemblyVersion"] = assemblyVersion; var lastVersion = 0; var gitConfiguration = appConfigurator.Of <GitConfiguration>(); if (fieldCount == 3 && gitConfiguration.GitCount != null) { Log.Info($"GitCount: {gitConfiguration.GitCount}"); lastVersion = gitConfiguration.GitCount.Value; } var appVersion = fieldCount == 3 ? $"{assemblyVersion}.{lastVersion}" : assemblyVersion; Log.Info($"app version: {appVersion}"); compileConfiguration.AppVersion = appVersion; } else { throw new ArgumentException($"Can not math VersionFormatRegex={formatRegex} in assmebly info file {file} \r\n The file content:\r\n{content}"); } }); }
static void Main(string[] args) { var msBuild = new MSBuild(AppConfigurator.GetAppConfigurator()); msBuild.Build(); }
static void Main(string[] args) { Parser.Default.ParseArguments <AssmeblyOption>(args).WithParsed(option => { var appConfigurator = AppConfigurator.GetAppConfigurator(); var compileConfiguration = appConfigurator.Of <CompileConfiguration>(); #if DEBUG var fileSniff = new FileSniff(appConfigurator); fileSniff.Sniff(); #endif var file = option.AssemblyInfoFile; if (string.IsNullOrEmpty(file)) { file = appConfigurator.Default["AssemblyInfoFile"]; } if (string.IsNullOrEmpty(file)) { throw new ArgumentException( $"Can not find AssemblyInfoFile, try to input --AssemblyInfoFile value"); } if (!Path.IsPathRooted(file)) { var codeDirectory = compileConfiguration.CodeDirectory; file = Path.Combine(codeDirectory, file); file = Path.GetFullPath(file); } appConfigurator.Default["AssemblyInfoFile"] = file; Log.Info($"assmebly info file: {file}"); if (!File.Exists(file)) { throw new ArgumentException($"The assmebly info file {file} can not be found."); } var formatRegex = option.VersionFormatRegex; if (string.IsNullOrEmpty(formatRegex)) { formatRegex = "Version = \\\"(\\d+.\\d+.\\d+)\\\";"; } Log.Info($"VersionFormatRegex: {formatRegex}"); var appVersion = option.AppVersion; if (string.IsNullOrEmpty(appVersion)) { appVersion = compileConfiguration.AppVersion; } if (string.IsNullOrEmpty(appVersion)) { throw new ArgumentException("Can not find app version from command line and configuration file"); } Log.Info($"app version: {appVersion}"); // 通过 formatRegex 找到匹配的 Assembly 文件的版本号,然后修改版本号,替换为从命令行参数传入的或通过配置读取的版本号 var content = File.ReadAllText(file); var match = Regex.Match(content, formatRegex); if (!match.Success) { throw new ArgumentException( $"Can not math VersionFormatRegex={formatRegex} in assmebly info file {file} \r\n The file content:\r\n{content}"); } content = content.Replace(match.Value, match.Value.Replace(match.Groups[1].Value, appVersion)); File.WriteAllText(file, content); Log.Info($"Wrote the app verion {appVersion} to assembly file {file}"); }); }
public static Git GetGitRepo() { var appConfigurator = AppConfigurator.GetAppConfigurator(); return(GetGitRepo(appConfigurator)); }
static void Main(string[] args) { var commandLine = dotnetCampus.Cli.CommandLine.Parse(args); var dictionary = commandLine.ToDictionary(); // 获取设备配置,要求执行 dotnet buildkit init 命令,执行之后才会将设备的配置和项目的配置进行合并。因此单独执行这个应用,也许会找不到用户名等 var appConfigurator = AppConfigurator.GetAppConfigurator(); appConfigurator.Merge(dictionary, "Email"); var emailConfiguration = appConfigurator.Of <EmailConfiguration>(); var smtpServer = emailConfiguration.SmtpServer; if (string.IsNullOrEmpty(smtpServer)) { throw new ArgumentException( $"找不到邮件 smtp 服务器地址,是否忘记调用 dotnet buildkit init 读取设备的配置。可在命令行传入 --{nameof(Options.SmtpServer)} 指定邮件服务器地址"); } // 忽略了…… var port = emailConfiguration.SmtpServerPort; // 忽略对用户名和密码的判断 var userName = emailConfiguration.UserName; var password = emailConfiguration.Password; var displayName = emailConfiguration.SenderDisplayName; var from = userName; if (string.IsNullOrEmpty(displayName)) { displayName = userName; } var options = commandLine.As <Options>(); var to = options.To; if (string.IsNullOrEmpty(to)) { throw new ArgumentException($"必须通过 -t 或 --to 指定邮件接收方,多个接收方可采用 ; 分割"); } Console.WriteLine($"通过 {smtpServer}:{port} 发送 {options.Subject} 到 {to}"); if (string.IsNullOrEmpty(options.Subject)) { throw new ArgumentException( $"邮件主题不能为空,请使用 -{Options.SubjectCommand} 或 --{nameof(Options.Subject)}指定邮件主题"); } List <FileInfo>?attachmentFileList = null; if (!string.IsNullOrEmpty(options.Files)) { attachmentFileList = new List <FileInfo>(); foreach (string file in options.Files.Split('|').Where(temp => !string.IsNullOrEmpty(temp)) .Select(Path.GetFullPath)) { if (!File.Exists(file)) { throw new ArgumentException($"指定传入文件,但找不到 {file} 文件"); } attachmentFileList.Add(new FileInfo(file)); } } var toList = to.Split(';') // 使用 Trim(),因为经常写 ` ;` 或者 `; ` 的字符串 .Select(temp => temp.Trim()); EmailHelper.SendEmail(smtpServer, port !.Value, userName !, password !, from !, displayName !, toList, options.Subject !, options.Body ?? string.Empty, attachmentFileList); }