基于DotNetty实现自动发布 - 项目的配置与发现

前言

上一篇,我们实现了基于 DotNetty 的通信基础模块的搭建,本篇,主要实现待发布 Web 项目的集成。

创建待发布项目

  • 为了测试, 我创建了一个基于 .NET 4.8 的 Web 项目 OpenDeploy.TestWebProject

  • 我本机的代码仓储路径是: D:\Projects\Back\dotnet\Study\OpenDeploy.TestWebProject

待发布项目集成 Git

Git 是一个开源的分布式版本控制系统。我们使用它实现自动化检测需要发布的文件。

配置待发布项目

  • 先放一下实现的效果图, 因为我对 WPF 也不是很精通,不足之处请大家见谅



  • 客户端基于 WPF 实现
  • 数据持久化使用的 SQLite
  • 增加了几个常用的 Git 命令
  • 简单贴点代码,其他请大家看源码吧,最下面有地址

解决方案模型

C# 复制代码
/// <summary> 解决方案领域模型 </summary>
[Table("Solution")]
public class Solution
{
    [Key]
    public int Id { get; set; }

    /// <summary> 解决方案名称 </summary>
    public string SolutionName { get; set; } = string.Empty;

    /// <summary> 解决方案Git仓储路径 </summary>
    public string GitRepositoryPath { get; set; } = string.Empty;
}

确定配置解决方案

C# 复制代码
/// <summary> 确定配置解决方案 </summary>
[RelayCommand]
private void OkConfigSolution()
{
    try
    {
        if (string.IsNullOrEmpty(ConfigSolution.SolutionName))
        {
            throw new Exception("请填写解决方案名称");
        }
        if (!GitHelper.IsValidRepository(ConfigSolution.GitRepositoryPath))
        {
            throw new Exception("非法的Git仓储路径");
        }
    }
    catch (Exception ex)
    {
        Growl.ClearGlobal();
        Growl.WarningGlobal(ex.Message);
        return;
    }

    //持久化到Sqlite
    solutionRepository.AddSolution(ConfigSolution.Map2Entity());

    Growl.SuccessGlobal("操作成功");

    //重新加载解决方案
    LoadSolutions();

    //关闭弹窗
    configSolutionDialog?.Close();
}

执行 Git 命令

C# 复制代码
    /// <summary> 执行git命令 </summary>
    private async Task RunGitCommand(string cmd)
    {
        var loading = Loading.Show();
        string output = string.Empty;
        LogText = string.Empty;

        await Task.Run(() =>
        {
            var _process = new Process();
            _process.StartInfo.WorkingDirectory = GitRepositoryPath;
            _process.StartInfo.FileName = "cmd.exe";
            _process.StartInfo.Arguments = "/C " + cmd;
            _process.StartInfo.UseShellExecute = false;
            _process.StartInfo.CreateNoWindow = true;
            _process.StartInfo.RedirectStandardInput = true;
            _process.StartInfo.RedirectStandardOutput = true;
            _process.StartInfo.RedirectStandardError = true;
            _process.Start();//启动程序

            output = _process.StandardOutput.ReadToEnd();

            if (string.IsNullOrEmpty(output))
            {
                output = _process.StandardError.ReadToEnd();
                if (string.IsNullOrEmpty(output))
                {
                    output = "没有返回值";
                }
            }

            _process.WaitForExit();
            _process.Close();
        });

        LogText = output;
        loading.Close();
    }

总结

至此,我们实现了待发布项目的配置与发现,简单集成了常用的 Git 命令等

代码仓库

项目暂且就叫 OpenDeploy

欢迎大家拍砖,Star

下一步

计划下一步,实现一键发布,自动检测到自上次发布以来的代码变化,自动识别要发布的文件,一次性打包通过 DotNetty 发送到服务器

相关推荐
Aurora_th1 小时前
浙江海洋大学 资料共享 期末考试卷、课程资料等
git·github
Now喔1 小时前
WPF画刷介绍
wpf
奶茶树4 小时前
【C++】13. C++11新特性【上】
c语言·开发语言·c++·git·github
李高钢8 小时前
WPF/WinForms 客户端通过 gRPC 与后端通信:从 Proto 契约到流式调用的完整指南
wpf·grpc·winforms
夏至春来-美美19 小时前
git clone报错
git
拂拉氏19 小时前
【Linux】 开发工具(Makefile、git、cgdb)解析与对于操作系统的基础认识
linux·git·操作系统·makefile·cgdb
番茄不是西红柿kk1 天前
deepseek-harness跨平台桌面端二开项目(附git仓库地址+安装包)
git·agent·codex·deepseek·deepseekharness
一见已难忘1 天前
基于 Harmony 6.0 应用的宠物寄养预约系统实现
wpf·宠物
fl1768311 天前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf
李高钢1 天前
【WPF】高级 UI 与性能优化实战:从卡顿到丝滑
ui·性能优化·wpf