コード例 #1
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile("secrets.json", optional: false, reloadOnChange: true);

            IConfigurationRoot configuration = builder.Build();


            Console.WriteLine("Retrieving token from key vault...");
            var devOpsToken = configuration["AzureDevOpsInstallerToken"];

            var devOpsSettingSection = configuration.GetSection("DevOpsEnvironmentSettings");

            var organizationUri = GetSetting(devOpsSettingSection, "OrganizationUri");
            var projectName     = GetSetting(devOpsSettingSection, "ProjecName");
            var projectGuid     = GetSetting(devOpsSettingSection, "ProjectGuid");
            var username        = GetSetting(devOpsSettingSection, "Username");

            Console.WriteLine("Connecting Dev Ops organization...");
            var devOpsService = new AzureDevOpsService(organizationUri, username, devOpsToken, new Guid(projectGuid));

            Console.WriteLine("Retrieving build data...");
            var lastBuild = devOpsService.GetProjectBuilds()
                            .Result
                            .OrderByDescending(k => k.LastChangedDate)
                            .FirstOrDefault();

            Console.WriteLine("Downloading zip from artifactor...");

            if (File.Exists(FilePath))
            {
                File.Delete(FilePath);
            }
            CreateNewDirectory(ArtifactorExtractionFolder);
            //CreateNewDirectory(AssemblyCliExtractionFolder);

            Stream zipStream = devOpsService.GetArtifact(lastBuild.Id, ArtifactName).Result;

            using (FileStream zipFile = new FileStream(FilePath, FileMode.Append))
            {
                zipStream.CopyTo(zipFile);
            }


            Console.WriteLine("Unzipping artifactor...");
            ZipFile.ExtractToDirectory(FilePath, ArtifactorExtractionFolder);
            var assemblyCliZipFileName         = $@"{ArtifactorExtractionFolder}\Assembly\DDCli\{lastBuild.Id}.zip";
            var assemblyCliDynamicsZipFileName = $@"{ArtifactorExtractionFolder}\Assembly\DDCli.Dynamics\{lastBuild.Id}.zip";

            Console.WriteLine("Unzipping assemblies...");


            DeleteDirectory(AssemblyCliExtractionFolder);
            DeleteDirectory(AssemblyCliDynamicsExtractionFolder);

            ZipFile.ExtractToDirectory(assemblyCliZipFileName, AssemblyCliExtractionFolder);
            ZipFile.ExtractToDirectory(assemblyCliDynamicsZipFileName, AssemblyCliDynamicsExtractionFolder);
            Console.WriteLine("Installing files in folder...");
            if (Directory.Exists(InstallCliFolder))
            {
                Directory.Delete(InstallCliFolder, true);
            }
            if (Directory.Exists(InstallCliDynamicsFolder))
            {
                Directory.Delete(InstallCliDynamicsFolder, true);
            }
            Directory.Move(AssemblyCliExtractionFolder, InstallCliFolder);
            Directory.Move(AssemblyCliDynamicsExtractionFolder, InstallCliDynamicsFolder);
            Console.WriteLine("Installation complete");
        }