Skip to content

Commit 8e414a7

Browse files
committed
Augment OfficialBuild attribute with version
1 parent 0d1788e commit 8e414a7

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

Directory.Build.targets

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project>
2+
<PropertyGroup>
3+
<DeployPropertiesFile>DeployProperties.g.cs</DeployPropertiesFile>
4+
</PropertyGroup>
5+
6+
<Target Name="WriteDeployProperties" BeforeTargets="BeforeCompile;CoreCompile" Outputs="$(IntermediateOutputPath)$(DeployPropertiesFile)">
7+
<PropertyGroup>
8+
<DeployPropertiesFilePath>$(IntermediateOutputPath)$(DeployPropertiesFile)</DeployPropertiesFilePath>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<DeployAttributes Include="osu.Game.Utils.OfficialBuildAttribute">
13+
<_Parameter1>$(Version)</_Parameter1>
14+
</DeployAttributes>
15+
</ItemGroup>
16+
17+
<WriteCodeFragment AssemblyAttributes="@(DeployAttributes)" Language="C#" OutputFile="$(DeployPropertiesFilePath)">
18+
<Output TaskParameter="OutputFile" ItemName="Compile"/>
19+
<Output TaskParameter="OutputFile" ItemName="FileWrites"/>
20+
</WriteCodeFragment>
21+
</Target>
22+
</Project>

osu.Game/OsuGameBase.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,9 @@ public virtual string Version
125125
if (!IsDeployedBuild)
126126
return @"local " + (DebugUtils.IsDebugBuild ? @"debug" : @"release");
127127

128-
string informationalVersion = Assembly.GetEntryAssembly()?
129-
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
130-
.InformationalVersion;
131-
132-
// Example: [assembly: AssemblyInformationalVersion("2025.613.0-tachyon+d934e574b2539e8787956c3c9ecce9dadebb10ee")]
133-
if (!string.IsNullOrEmpty(informationalVersion))
134-
return informationalVersion.Split('+').First();
128+
OfficialBuildAttribute buildAttribute = RuntimeInfo.EntryAssembly.GetCustomAttribute<OfficialBuildAttribute>();
129+
if (buildAttribute != null)
130+
return buildAttribute.Version;
135131

136132
Version version = AssemblyVersion;
137133
return $@"{version.Major}.{version.Minor}.{version.Build}-lazer";

osu.Game/Utils/OfficialBuildAttribute.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,23 @@
22
// See the LICENCE file in the repository root for full licence text.
33

44
using System;
5-
using JetBrains.Annotations;
65

76
namespace osu.Game.Utils
87
{
9-
[UsedImplicitly]
8+
/// <summary>
9+
/// This attribute is automatically attached to assemblies of projects built with a <c>Version</c> property specified.
10+
/// It is purely informational - used to alert the user of the (lack of) online capabilities and of the game's version.
11+
/// <p />
12+
/// Refer to <c>Deploy.props</c> in the repository root for how this attribute is attached.
13+
/// </summary>
1014
[AttributeUsage(AttributeTargets.Assembly)]
11-
public class OfficialBuildAttribute : Attribute;
15+
public class OfficialBuildAttribute : Attribute
16+
{
17+
public readonly string Version;
18+
19+
public OfficialBuildAttribute(string version)
20+
{
21+
Version = version;
22+
}
23+
}
1224
}

0 commit comments

Comments
 (0)