Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (66 loc) · 2.03 KB
/
Copy pathProgram.cs
File metadata and controls
72 lines (66 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using SimpleGitVersion;
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
var logger = new StringLogger();
string? outPath = null;
int idxOutDir = Array.IndexOf( args, "--out-file" );
if( idxOutDir >= 0 )
{
if( args.Length == idxOutDir )
{
logger.Error( "Missing output file path argument." );
}
else
{
outPath = args[idxOutDir + 1];
if( string.IsNullOrWhiteSpace( outPath ) || outPath.AsSpan().ContainsAny( Path.GetInvalidPathChars() ) )
{
logger.Error( "Invalid output file path." );
outPath = null;
}
else
{
try
{
outPath = Path.GetFullPath( Path.Combine( Environment.CurrentDirectory, outPath ) );
var directory = Path.GetDirectoryName( outPath );
if( directory == null )
{
logger.Error( "Invalid output file path." );
outPath = null;
}
else
{
if( !Directory.Exists( directory ) )
{
logger.Info( $"Creating output folder '{directory}'." );
Directory.CreateDirectory( directory );
}
}
}
catch( Exception ex )
{
logger.Error( $"Error while computing output directory '{outPath}' ({ex.Message})." );
outPath = null;
}
}
}
}
var info = CommitInfo.LoadFromPath( logger, Environment.CurrentDirectory );
info.Explain( logger );
var finalBuildInfo = info.FinalBuildInfo;
if( outPath != null )
{
File.WriteAllText( outPath, $"""
{finalBuildInfo.Version}
{finalBuildInfo.AssemblyVersion}
{finalBuildInfo.FileVersion}
{finalBuildInfo.InformationalVersion}
{finalBuildInfo.BuildConfiguration}
{info.RepositoryInfo.RemoteUrl}
""" );
}
Console.Write( logger.Conclude( finalBuildInfo ) );
return info.Error != null ? -1 : 0;