Skip to content

Commit 1c93200

Browse files
committed
build: fix build in environments without git repository
1 parent d7bd153 commit 1c93200

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<RollForward>LatestMajor</RollForward>
2626
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
2727
</PropertyGroup>
28+
<PropertyGroup Condition="!Exists('.git')">
29+
<UpdateAssemblyInfo>false</UpdateAssemblyInfo>
30+
<DisableGitVersionTask>true</DisableGitVersionTask>
31+
32+
<Version Condition="'$(VERSION)' != ''">$(VERSION)</Version>
33+
</PropertyGroup>
2834
<PropertyGroup Condition="$([MSBuild]::IsOsPlatform('Windows')) and
2935
('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">
3036
<UseCurrentRuntimeIdentifier>true</UseCurrentRuntimeIdentifier>

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
assembly-informational-format: '{SemVer}+g{ShortSha}'
2-
commit-date-format: "yyyy-MM-dd HH:mm:ss zzzz"
2+
commit-date-format: "yyyy-MM-dd hh:mm:ss zzzz"
33
update-build-number: true
44
semantic-version-format: Strict
55
mode: ContinuousDelivery

SnapX.CommonUI/AboutDialog.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public virtual void Show()
1212

1313
public virtual string GetSystemInfo()
1414
{
15-
return SnapX.Core.Utils.OsInfo.GetFancyOSNameAndVersion();
15+
return Core.Utils.OsInfo.GetFancyOSNameAndVersion();
1616
}
1717
public virtual string GetTitle() => Core.SnapX.Title;
1818
public virtual string GetLicense() => "GPL v3 or Later";
@@ -32,27 +32,26 @@ public virtual string GetCopyright() =>
3232
public virtual string GetRuntime() => System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
3333
public virtual string GetOsPlatform() => $"{Environment.OSVersion.Platform} {Environment.OSVersion.Version}";
3434
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
35-
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(GitVersionInformation))]
3635
[RequiresUnreferencedCode("Uses reflection to access properties that may be removed by the trimmer.")]
3736
public virtual string GetBuildInformation()
3837
{
3938
var title = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>()?.Title ?? Assembly.GetExecutingAssembly().FullName;
4039
var flags = string.Join(", ", Core.SnapX.Flags);
4140
var informationalVersion = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "Unknown";
42-
43-
var type = typeof(GitVersionInformation);
44-
var gitCommitId = type.GetField("Sha", BindingFlags.Public | BindingFlags.Static)?.GetValue(null) as string;
45-
var commitDateStr = type.GetField("CommitDate", BindingFlags.Public | BindingFlags.Static)?.GetValue(null) as string;
41+
var fileVersion = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "Unknown";
42+
var type = Type.GetType("GitVersionInformation");
43+
var gitCommitId = type?.GetField("Sha", BindingFlags.Public | BindingFlags.Static)?.GetValue(null) as string;
44+
var commitDateStr = type?.GetField("CommitDate", BindingFlags.Public | BindingFlags.Static)?.GetValue(null) as string;
4645
var gitCommitDate = DateTime.TryParse(commitDateStr, out var parsedDate)
4746
? parsedDate
4847
: new DateTime();
49-
var branchName = type.GetField("BranchName", BindingFlags.Public | BindingFlags.Static)?.GetValue(null)?.ToString();
48+
var branchName = type?.GetField("BranchName", BindingFlags.Public | BindingFlags.Static)?.GetValue(null)?.ToString();
5049

51-
return $"{title} v{GitVersionInformation.AssemblySemFileVer}{Environment.NewLine}" +
50+
return $"{title} v{fileVersion}{Environment.NewLine}" +
5251
$"Flags: {flags}{Environment.NewLine}" +
5352
$"Build: {Core.SnapX.Build}{Environment.NewLine}" +
5453
$"Informational Version: {informationalVersion} (Branch: {branchName}){Environment.NewLine}" +
55-
$"Commit {gitCommitId} ({gitCommitDate})";
54+
$"Commit {gitCommitId} ({gitCommitDate.ToLocalTime()})";
5655
}
5756
public virtual string GetOsArchitecture() => System.Runtime.InteropServices.RuntimeInformation.OSArchitecture.ToString();
5857

SnapX.CommonUI/SnapX.CommonUI.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
</PropertyGroup>
88
<ItemGroup>
99
<ProjectReference Include="..\SnapX.Core\SnapX.Core.csproj" />
10+
<!-- GitVersion class must not be trimmed -->
11+
<TrimmerRootAssembly Include="$(AssemblyName)" />
1012
</ItemGroup>
1113
</Project>

0 commit comments

Comments
 (0)