前面在介绍Git Repo的时候有上传了几个C#的Project,里面只有几行简单的程序,是为了接下来的CI/CD Pipeline文章而准备,不过当时只有上传到Git Repo,并没有介绍说明它们,这边就用简短的篇幅来了解一下到底有哪些内容吧!
首先,有个2021ironman的Solution方案档,里面有3个C#专案,分别是ConsoleApp、ModuleA、ModuleBase:
ModuleBase中只有一个IModuleInfo.cs,程序码如下:
using System;
using System.Collections.Generic;
using System.Text;
namespace ModuleBase
{
public interface IModuleInfo
{
public string Name { get; }
public string Description { get; }
void EntryPoint();
}
}
ModuleA里面只有一个Startup.cs,程序码如下:
using System;
namespace ModuleA
{
public class Startup : ModuleBase.IModuleInfo
{
public string Name => "ModuleA";
public string Description => "ModuleA is a test module.";
public void EntryPoint()
{
Console.WriteLine("Hello world, this is ModuleA.");
}
}
}
接着是ConsoleApp的Program.cs,程序码如下:
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Runtime.Loader;
using ModuleBase;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo modulesDir = new DirectoryInfo("modules");
Console.WriteLine("Hello World! This is Console app.");
if (modulesDir.Exists)
{
var dlls = modulesDir.GetFiles("*.dll", SearchOption.AllDirectories);
List<Assembly> assemblies = new List<Assembly>();
foreach (var dll in dlls)
{
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(dll.FullName);
foreach (var type in assembly.GetTypes())
{
if (typeof(IModuleInfo).IsAssignableFrom(type) && !type.IsInterface)
{
IModuleInfo moduleInfo = Activator.CreateInstance(type) as IModuleInfo;
Console.WriteLine($"Load {moduleInfo.Name}, {moduleInfo.Description}.");
moduleInfo.EntryPoint();
}
}
}
}
Console.ReadLine();
}
}
}
ModuleBase这个Class Library作为定义Module的基础,虽然目前只有ModuleA,但是之後的ModuleB、ModuleC都要以ModuleBase为基底,所以ModuleBase会在後续用来制作成nuget package,在Azure DevOps中建立私有的nuget套件库。
ModuleA实作ModuleBase中所定义的介面,如上面所说,之後会有ModuleB、ModuleC,如果每一个Module都替它们建立一个专属的Pipeline,那数量会很可观,所以之後建立的Pipeline中,会有一个是设计成可以让使用者来告诉Pipeline应该要选择哪一个来建置(Build)。
ConsoleApp的部份则是扮演主程序的角色,这里也只是把Module的dll载入之後执行输出结果而已,暂时没有特别的用途。
初期就先以上面这些东西来准备接下来的Pipeline范例,下一篇我们就要实际来建立Pipeline了。
<<: [Day15] Andoroid - Kotlin笔记: MVVM简介
>>: 【在厨房想30天的演算法】Day 03 那个时间复杂度会让人生变复杂吗?
今天继续介绍 NetSuite 几个基本的 Glossary, 这些 Glossary 经常会出现在...
今天继续记录一些 Mac的功能。 四角设定 非常好用的功能,只要将滑鼠移动到画面4个角落,就可以触发...
T0831 Manipulation of Control 攻击者针对工控环境中的设备进行控制,主要...
在 Day 22 所提到的 Ctop 好用的 docker 容器监控工具 毕竟还是在命令列上,对於现...
对PostBack Event中的字串进行处理,由於这个参数仅能放入字串,所以可以套用网页Query...