Skip to content

Commit

Permalink
更新发布程序
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuDanK committed Jan 9, 2023
1 parent 5239ce9 commit 497c42d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
14 changes: 14 additions & 0 deletions SageTools.Console/Extension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Linq;
using SageTools.Extension;

namespace SageTools.Console;

public static class Extension
{
public static string GetArgValue(this string[] args, string argKey)
{
if (args.IsNullOrEmpty() || argKey.IsNullOrWhiteSpace()) return default;
argKey = '-' + argKey.TrimStart('-').TrimEnd('=') + '=';
return args.Where(x => x.Contains(argKey)).Select(x => x.Replace(argKey, "")).FirstOrDefault();
}
}
37 changes: 20 additions & 17 deletions SageTools.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System;
using System.IO;
using SageTools.Extension;
using System.Linq;
using System.Xml;
using SageTools.Extension;

namespace SageTools.Console
{
internal class Program
{
static void Main(string[] args)
private static void Main(string[] args)
{
var help = args.Any(x => x.Contains("-h"));
if (help)
Expand All @@ -17,42 +17,45 @@ static void Main(string[] args)
Environment.Exit(0);
}
System.Console.WriteLine("处理xml文件");
var source = args.Where(x => x.Contains("-source=")).Select(x => x.Replace("-source=", "")).FirstOrDefault();
var step = args.Where(x => x.Contains("-step=")).Select(x => x.Replace("-step=", "")).FirstOrDefault();
var version = args.Where(x => x.Contains("-version=")).Select(x => x.Replace("-version=", "")).FirstOrDefault();
if (source.IsNullOrEmpty())
{
System.Console.WriteLine("执行错误:必须指定 -source");
Environment.Exit(-1);
}
var source = args.GetArgValue("source");
var step = args.GetArgValue("step");
var version = args.GetArgValue("version");

var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, source);
if (!File.Exists(path))
{
System.Console.WriteLine($"执行错误:【{path}】文件不存在");
Environment.Exit(-1);
}
var xmlDoc = new XmlDocument(); //新建XML文件
xmlDoc.Load(path); //加载XML文件
var xmlDoc = new XmlDocument();
xmlDoc.Load(path);
var versionNode = xmlDoc.DocumentElement?.SelectSingleNode("PropertyGroup")?.SelectSingleNode("Version");
if (versionNode == null)
if (versionNode.IsNull())
{
System.Console.WriteLine("执行错误:项目没有配置版本号");
Environment.Exit(-1);
}
if (version.IsNullOrEmpty())
{
version = versionNode.InnerText;
var lastNum = version.Substring(version.LastIndexOf(".", StringComparison.Ordinal) + 1);
version = versionNode!.InnerText;
var lastNum = version[(version.LastIndexOf(".", StringComparison.Ordinal) + 1)..];
var newNum = lastNum.ToInt32() + step;
var newVersion = version.Substring(0, version.LastIndexOf(".", StringComparison.Ordinal) + 1) + newNum;
var newVersion = version[..(version.LastIndexOf(".", StringComparison.Ordinal) + 1)] + newNum;
versionNode.InnerText = newVersion;
System.Console.WriteLine($"当前版本{version},末尾版本号{lastNum},新版本号{newVersion}");
}
else
{
System.Console.WriteLine($"直接指定新版本号为 {version}");
versionNode.InnerText = version;
versionNode!.InnerText = version;
}

var copyright = xmlDoc.DocumentElement?.SelectSingleNode("PropertyGroup")?.SelectSingleNode("Copyright");
if (copyright.IsNotNull())
{
copyright!.InnerText = $"Copyright © LiuDanK 2021-{DateTime.Now.Year}";
}

xmlDoc.Save(path);
System.Console.WriteLine("处理完毕!");
}
Expand Down
7 changes: 7 additions & 0 deletions SageTools.Console/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"SageTools.Console": {
"commandName": "Project"
}
}
}
6 changes: 2 additions & 4 deletions SageTools/SageTools.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>LiuDanK</Authors>
<Company>LiuDanK</Company>
<Description>常用工具类、拓展方法等封装,目前还在实现中</Description>
<Copyright>Copyright © LiuDanK 2021</Copyright>
<Version>1.0.0</Version>
<Version>1.8.6</Version>
</PropertyGroup>

</Project>
</Project>

0 comments on commit 497c42d

Please sign in to comment.