forked from GitTools/GitVersion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitVersionOutputTool.cs
73 lines (66 loc) · 3 KB
/
GitVersionOutputTool.cs
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
71
72
73
using GitVersion.Extensions;
using GitVersion.Output.AssemblyInfo;
using GitVersion.Output.GitVersionInfo;
using GitVersion.Output.OutputGenerator;
using GitVersion.Output.WixUpdater;
using GitVersion.OutputVariables;
using Microsoft.Extensions.Options;
namespace GitVersion;
internal class GitVersionOutputTool(
IOptions<GitVersionOptions> options,
IOutputGenerator outputGenerator,
IWixVersionFileUpdater wixVersionFileUpdater,
IGitVersionInfoGenerator gitVersionInfoGenerator,
IAssemblyInfoFileUpdater assemblyInfoFileUpdater,
IProjectFileUpdater projectFileUpdater)
: IGitVersionOutputTool
{
private readonly GitVersionOptions gitVersionOptions = options.Value.NotNull();
private readonly IOutputGenerator outputGenerator = outputGenerator.NotNull();
private readonly IWixVersionFileUpdater wixVersionFileUpdater = wixVersionFileUpdater.NotNull();
private readonly IGitVersionInfoGenerator gitVersionInfoGenerator = gitVersionInfoGenerator.NotNull();
private readonly IAssemblyInfoFileUpdater assemblyInfoFileUpdater = assemblyInfoFileUpdater.NotNull();
private readonly IProjectFileUpdater projectFileUpdater = projectFileUpdater.NotNull();
public void OutputVariables(GitVersionVariables variables, bool updateBuildNumber)
{
using (this.outputGenerator)
{
this.outputGenerator.Execute(variables, new OutputContext(gitVersionOptions.WorkingDirectory, gitVersionOptions.OutputFile, updateBuildNumber));
}
}
public void UpdateAssemblyInfo(GitVersionVariables variables)
{
var assemblyInfoContext = new AssemblyInfoContext(gitVersionOptions.WorkingDirectory, gitVersionOptions.AssemblySettingsInfo.EnsureAssemblyInfo, [.. gitVersionOptions.AssemblySettingsInfo.Files]);
if (gitVersionOptions.AssemblySettingsInfo.UpdateProjectFiles)
{
using (this.projectFileUpdater)
{
this.projectFileUpdater.Execute(variables, assemblyInfoContext);
}
}
else if (gitVersionOptions.AssemblySettingsInfo.UpdateAssemblyInfo)
{
using (this.assemblyInfoFileUpdater)
{
this.assemblyInfoFileUpdater.Execute(variables, assemblyInfoContext);
}
}
}
public void UpdateWixVersionFile(GitVersionVariables variables)
{
if (gitVersionOptions.WixInfo.UpdateWixVersionFile)
{
using (this.wixVersionFileUpdater)
{
this.wixVersionFileUpdater.Execute(variables, new WixVersionContext(gitVersionOptions.WorkingDirectory));
}
}
}
public void GenerateGitVersionInformation(GitVersionVariables variables, FileWriteInfo fileWriteInfo, string? targetNamespace = null)
{
using (this.gitVersionInfoGenerator)
{
this.gitVersionInfoGenerator.Execute(variables, new GitVersionInfoContext(gitVersionOptions.WorkingDirectory, fileWriteInfo.FileName, fileWriteInfo.FileExtension, targetNamespace));
}
}
}