public static void AddCommandLine(this IAppConfigurator appConfigurator, string[] args,
                                          Dictionary <string, string> switchMapping)
        {
            for (var i = 0; i < args.Length; i++)
            {
                var arg = args[i];
                if (arg.Length <= 1)
                {
                    continue;
                }
                var argName = TryGetArgName(switchMapping, arg);

                if (string.IsNullOrEmpty(argName))
                {
                    continue;
                }

                var argValue = "true";

                if (i < args.Length - 1)
                {
                    var nextArg = args[i + 1];
                    if (nextArg.Length <= 1 || nextArg[0] != '-')
                    {
                        argValue = nextArg;
                    }
                }

                appConfigurator.Default[argName] = argValue;
            }
        }
        /// <summary>
        /// 协助部署使用的,用于协助将所有的构建需要的命令更新
        /// </summary>
        /// <param name="appConfigurator"></param>
        private static void CheckCommandInstall(IAppConfigurator appConfigurator)
        {
            var localToolList = new List <string>
            {
                "dotnetCampus.GitRevisionTask",
                "dotnetCampus.NuGetTask",
                "dotnetCampus.DotNETTask",
                "dotnetCampus.GetAssemblyVersionTask",
                "dotnetCampus.WriteAppVersionTask",
                "dotnetCampus.MatrixRun",
                "dotnetCampus.NuGetPublishTask",
                "dotnetCampus.PickTextValueTask",
                "dotnetCampus.SendEmailTask",
                "dotnetCampus.BuildMd5Task",

                // 用于 Tag 打包
                // https://github.com/dotnet-campus/dotnetCampus.TagToVersion
                "dotnetCampus.TagToVersion",
                // 用于更新所有的 dotnet tool 工具
                // https://github.com/dotnet-campus/dotnetCampus.UpdateAllDotNetTools
                "dotnetCampus.UpdateAllDotNetTools",
                // 用于下载文件
                // https://github.com/dotnet-campus/dotnetCampus.FileDownloader
                "dotnetCampus.FileDownloader.Tool",
            };

            // 读取全局配置的工具
            var configToolList = appConfigurator.Of <ToolConfiguration>().DotNETToolList;

            Log.Debug("开始确认工具准备完成");
            localToolList.AddRange(configToolList);
            var dotNetTool = new DotNet(appConfigurator);

            dotNetTool.TryInstall(localToolList);
        }
        static void Main(string[] args)
        {
            try
            {
                var config = "build.fkv";
                Console.WriteLine($"命令行 " + Environment.CommandLine);

                config = Path.GetFullPath(config);
                Console.WriteLine($"配置文件 {config}");

                AppConfigurator.SetConfigurationFile(new FileInfo(config));

                var fileConfigurationRepo        = ConfigurationFactory.FromFile(config);
                IAppConfigurator appConfigurator = fileConfigurationRepo.CreateAppConfigurator();

                var compiler = new Compiler(appConfigurator);
                compiler.Compile();

                if (args.Any(temp => temp == "publish"))
                {
                    compiler.Nuget.PublishNupkg();
                }
            }
            catch (Exception e)
            {
                // 可能日志出现异常,因此就不通过日志库输出
                Console.WriteLine(e);
                Log.Error(e.ToString());

                Environment.Exit(-1);
            }
        }
        /// <summary>
        /// 创建构建过程使用的工具
        /// </summary>
        /// <param name="appConfigurator"></param>
        /// <param name="logger"></param>
        protected DotNetBuildTool(IAppConfigurator appConfigurator, ILogger logger = null)
        {
            AppConfigurator = appConfigurator
                              ?? dotnetCampus.DotNETBuild.Context.AppConfigurator.GetAppConfigurator();

            Logger = logger ?? AppConfigurator.Of <LogConfiguration>().GetLogger();
        }
Exemple #5
0
        public static Git GetGitRepo(IAppConfigurator appConfigurator)
        {
            // 先尝试从项目配置获取
            var compileConfiguration = appConfigurator.Of <CompileConfiguration>();
            var codeDirectory        = compileConfiguration.CodeDirectory;

            if (string.IsNullOrEmpty(codeDirectory))
            {
                // 也就是现在还没找过这个文件夹
                var fileSniff = new FileSniff(appConfigurator);
                fileSniff.Sniff();
            }
            codeDirectory = compileConfiguration.CodeDirectory;
            if (string.IsNullOrEmpty(codeDirectory))
            {
                throw new ArgumentException("没有找到 git 仓库文件夹,请确定当前项目被 Git 管理 当前工作路径:" + Environment.CurrentDirectory);
            }

            var git = new Git(new DirectoryInfo(codeDirectory))
            {
                NeedWriteLog = false,
            };

            return(git);
        }
Exemple #6
0
        private static FileInfo GetCurrentBuildLogFile(IAppConfigurator appConfigurator)
        {
            var currentBuildLogFile = new FileInfo(Path.GetTempFileName());
            var logConfiguration    = appConfigurator.Of <LogConfiguration>();

            logConfiguration.BuildLogFile = currentBuildLogFile.FullName;
            return(currentBuildLogFile);
        }
Exemple #7
0
        internal static void SetAppConfigurator(IAppConfigurator appConfigurator)
        {
            if (_appConfigurator != null)
            {
                throw new InvalidOperationException("必须在调用 GetAppConfigurator 方法之前设置配置,请将设置配置的代码放在程序运行最前");
            }

            _appConfigurator = appConfigurator;
        }
        private static void SetCommonConfiguration(IAppConfigurator appConfigurator)
        {
            var sdkConfiguration = appConfigurator.Of <DotNETBuildSDKConfiguration>();

            if (sdkConfiguration.EnableSetCommonConfiguration)
            {
                var compileConfiguration = appConfigurator.Of <CompileConfiguration>();

                compileConfiguration.SetCommonConfiguration();
            }
        }
#pragma warning restore CS0618 // 类型或成员已过时

        /// <summary>
        /// 尝试重新加载此配置文件的外部修改(例如使用其他编辑器或其他客户端修改的部分)。
        /// <para>外部修改会自动同步到此配置中,但此同步不会立刻发生,所以如果你明确知道外部修改了文件后需要立刻重新加载外部修改,才需要调用此方法。</para>
        /// </summary>
        public static Task ReloadExternalChangesAsync(this IAppConfigurator configs)
        {
            if (configs is null)
            {
                throw new ArgumentNullException(nameof(configs));
            }

            if (configs.Of <DefaultConfiguration>().Repo is FileConfigurationRepo repo)
            {
                return(repo.ReloadExternalChangesAsync());
            }
            return(Task.FromResult <object?>(null));
        }
Exemple #10
0
 public MachineConfigurator(ISystemInitializer systemInitializer,
                            IManifestRepository manifestRepository,
                            IAppInstaller appInstaller,
                            IDownloadAppInstaller downloadAppInstaller,
                            IAppConfigurator appConfigurator,
                            IConsoleLogger consoleLogger)
 {
     this.systemInitializer    = systemInitializer;
     this.manifestRepository   = manifestRepository;
     this.appInstaller         = appInstaller;
     this.downloadAppInstaller = downloadAppInstaller;
     this.appConfigurator      = appConfigurator;
     this.consoleLogger        = consoleLogger;
 }
        /// <inheritdoc />
        public Compiler(IAppConfigurator appConfigurator = null, ILogger logger = null) : base(appConfigurator, logger)
        {
            _appConfigurator = appConfigurator;

            Init();

            Nuget = new NuGet(AppConfigurator);
#pragma warning disable CS0618
            MsBuild = new MsBuild(AppConfigurator);
#pragma warning restore CS0618
            MSBuild    = new MSBuild(AppConfigurator);
            TestHelper = new TestHelper(AppConfigurator);

            //_logger = logger ?? AppConfigurator.Of<LogConfiguration>().GetLogger();
        }
        public static IAppConfigurator AddCommandLine(
            this IAppConfigurator appConfigurator,
            string[] args,
            IDictionary <string, string>?switchMappings)
        {
            var commandLineConfigurationProvider = new CommandLineConfigurationProvider(args, switchMappings);
            var dictionary = commandLineConfigurationProvider.Load();

            foreach (var keyValuePair in dictionary)
            {
                appConfigurator.Default.SetValue(keyValuePair.Key, keyValuePair.Value);
            }

            return(appConfigurator);
        }
        public void WhenFileChanged()
        {
//            "监听后,文件内容发生了改变,可以读到文件的新值。".Test(async () =>
//            {
//                const string dcc = "configs.01.dcc";
//                IAppConfigurator configs = ConfigurationFactory.FromFile(dcc).CreateAppConfigurator();
//                var fake = configs.Of<FakeConfiguration>();
//                var oldValue = fake.Key;
//                Assert.AreEqual("Value", oldValue);
//                File.WriteAllText(dcc, @">
//Key
//NewValue
//>");
//                await configs.ReloadExternalChangesAsync().ConfigureAwait(false);
//                var newValue = fake.Key;
//                Assert.AreEqual("NewValue", newValue);
//            });

            "监听后,文件才被创建,可以读到文件中一开始就存放的值。".Test(async() =>
            {
                const string dcc         = "configs.new.dcc";
                IAppConfigurator configs = ConfigurationFactory.FromFile(dcc).CreateAppConfigurator();
                var fake     = configs.Of <FakeConfiguration>();
                var oldValue = fake.Key;
                Assert.AreEqual("", oldValue);
                File.WriteAllText(dcc, @">
Key
NewValue
>");
                await configs.ReloadExternalChangesAsync().ConfigureAwait(false);
                var newValue = fake.Key;
                Assert.AreEqual("NewValue", newValue);
            });

            "监听后,文件被删除,相当于所有未保存的值全部被删除。".Test(async() =>
            {
                const string dcc         = "configs.02.dcc";
                IAppConfigurator configs = ConfigurationFactory.FromFile(dcc).CreateAppConfigurator();
                var fake     = configs.Of <FakeConfiguration>();
                var oldValue = fake.Key;
                Assert.AreEqual("Value", oldValue);
                File.Delete(dcc);
                await configs.ReloadExternalChangesAsync().ConfigureAwait(false);
                var newValue = fake.Key;
                Assert.AreEqual("", newValue);
            });
        }
Exemple #14
0
        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;
            }
        }
Exemple #15
0
        /// <summary>
        /// 填充程序集信息,包括版本号
        /// </summary>
        /// <returns></returns>
        public static IAppConfigurator FillAssemblyInfo(this IAppConfigurator appConfigurator, Assembly assembly)
        {
            var compileConfiguration = appConfigurator.Of <CompileConfiguration>();

            var assemblyInformationalVersionAttribute = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>();

            if (string.IsNullOrEmpty(compileConfiguration.AppVersion))
            {
                compileConfiguration.AppVersion = assemblyInformationalVersionAttribute !.InformationalVersion;
            }

            if (string.IsNullOrEmpty(compileConfiguration.AssemblyVersion))
            {
                compileConfiguration.AssemblyVersion = assemblyInformationalVersionAttribute !.InformationalVersion;
            }

            return(appConfigurator);
        }
Exemple #16
0
        public static void Merge(this IAppConfigurator appConfigurator, Dictionary <string, string> dictionary,
                                 string configurationSectionName = "")
        {
            var configuration = appConfigurator.Default;

            if (!string.IsNullOrEmpty(configurationSectionName))
            {
                if (!configurationSectionName.EndsWith("."))
                {
                    configurationSectionName += ".";
                }
            }

            foreach (var(key, value) in dictionary)
            {
                if (!string.IsNullOrEmpty(value))
                {
                    configuration[$"{configurationSectionName}{key}"] = value;
                }
            }
        }
        public BinaryChopCompiler(IAppConfigurator appConfigurator,
                                  DirectoryInfo codeDirectory,
                                  DirectoryInfo targetDirectory,
                                  DirectoryInfo?outputDirectory = null,
                                  string?originBranch           = null,
                                  ILogger?logger = null)
        {
            AppConfigurator = appConfigurator;

            CodeDirectory   = codeDirectory;
            TargetDirectory = targetDirectory;

            if (logger is null)
            {
                var logConfiguration = appConfigurator.Of <LogConfiguration>();

                logger = logConfiguration.GetLogger();
            }

            Logger = logger;

            if (!string.IsNullOrEmpty(originBranch))
            {
                OriginBranch = originBranch;
            }

            var git = new Git(codeDirectory)
            {
                DefaultCommandTimeout = TimeSpan.FromMinutes(3)
            };

            _git = git;

            if (outputDirectory is null)
            {
                outputDirectory = new DirectoryInfo(Path.Combine(codeDirectory.FullName, "bin"));
            }

            OutputDirectory = outputDirectory;
        }
 /// <summary>
 /// 创建协助寻找文件
 /// </summary>
 /// <param name="appConfigurator"></param>
 public FileSniff(IAppConfigurator appConfigurator) : base(appConfigurator)
 {
 }
Exemple #19
0
 /// <inheritdoc />
 public NuGet(IAppConfigurator appConfigurator) : base(appConfigurator)
 {
 }
Exemple #20
0
 /// <inheritdoc />
 public MsBuildCompiler(IAppConfigurator appConfigurator) : base(appConfigurator)
 {
 }
 public static IAppConfigurator AddCommandLine(this IAppConfigurator appConfigurator,
                                               string[] args)
 {
     return(appConfigurator.AddCommandLine(args, switchMappings: null));
 }
Exemple #22
0
 public DotNet(IAppConfigurator appConfigurator) : base(appConfigurator)
 {
 }
 /// <inheritdoc />
 public MsBuild(IAppConfigurator appConfigurator) : base(appConfigurator)
 {
 }
 internal Startup(IConfiguration configuration, IAppConfigurator appConfigurator)
 {
     AppConfigurator = appConfigurator;
     Configuration   = configuration;
 }
 /// <inheritdoc />
 public TestHelper(IAppConfigurator appConfigurator)
 {
     AppConfigurator = appConfigurator;
 }