Skip to content

Commit a2f72ac

Browse files
Replace AssemblyInfo with ReleaseDateAttribute (#58)
Fixes #57
1 parent a2302d8 commit a2f72ac

File tree

8 files changed

+94
-78
lines changed

8 files changed

+94
-78
lines changed

IntelliTect.Multitool.Tests/IntelliTect.Multitool.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3+
<Import Project="../IntelliTect.Multitool/Build/IntelliTect.Multitool.targets"/>
34
<PropertyGroup>
45
<TargetFramework>netcoreapp3.1</TargetFramework>
56

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using Xunit;
3+
4+
namespace IntelliTect.Multitool.Tests;
5+
6+
public class ReleaseDateAttributeTests
7+
{
8+
[Fact]
9+
public void ReleaseDateIsGettingInjected()
10+
{
11+
DateTime? releaseDate = ReleaseDateAttribute.GetReleaseDate(GetType().Assembly);
12+
Assert.NotNull(releaseDate);
13+
Assert.Equal(DateTimeKind.Utc, releaseDate?.Kind);
14+
Assert.NotEqual(DateTime.MinValue, releaseDate);
15+
Assert.NotEqual(DateTime.MaxValue, releaseDate);
16+
}
17+
}

IntelliTect.Multitool.lutconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<LUTConfig Version="1.0">
2+
<Repository />
3+
<ParallelBuilds>true</ParallelBuilds>
4+
<ParallelTestRuns>true</ParallelTestRuns>
5+
<TestCaseTimeout>180000</TestCaseTimeout>
6+
</LUTConfig>

IntelliTect.Multitool/AssemblyInfo.cs

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
<ItemGroup>
3+
<AssemblyAttribute Include="IntelliTect.Multitool.ReleaseDate">
4+
<_Parameter1>$([System.DateTime]::UtcNow.ToString("O"))</_Parameter1>
5+
</AssemblyAttribute>
6+
</ItemGroup>
7+
</Project>
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<TargetFramework>netstandard2.1</TargetFramework>
4-
<OutputType>Library</OutputType>
5-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6-
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7-
<Company>IntelliTect-Nuget</Company>
8-
<Description>A utility library for IntelliTect</Description>
9-
<Copyright>Copyright © IntelliTect 2019</Copyright>
10-
<PackageTags>IntelliTect, Utilities, Multitool</PackageTags>
11-
<RepositoryType>git</RepositoryType>
12-
<Deterministic>true</Deterministic>
13-
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
14-
<NeutralLanguage>en</NeutralLanguage>
15-
<Version>1.0.1</Version>
16-
</PropertyGroup>
17-
<ItemGroup>
18-
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
19-
</ItemGroup>
20-
<ItemGroup>
21-
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0">
22-
<PrivateAssets>all</PrivateAssets>
23-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24-
</PackageReference>
25-
</ItemGroup>
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.1</TargetFramework>
4+
<OutputType>Library</OutputType>
5+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
6+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7+
<Company>IntelliTect-Nuget</Company>
8+
<Description>A utility library for IntelliTect</Description>
9+
<Copyright>Copyright © IntelliTect 2019</Copyright>
10+
<PackageTags>IntelliTect, Utilities, Multitool</PackageTags>
11+
<RepositoryType>git</RepositoryType>
12+
<Deterministic>true</Deterministic>
13+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
14+
<NeutralLanguage>en</NeutralLanguage>
15+
<Version>1.0.1</Version>
16+
</PropertyGroup>
17+
<ItemGroup>
18+
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0">
22+
<PrivateAssets>all</PrivateAssets>
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
</PackageReference>
25+
</ItemGroup>
26+
<ItemGroup>
27+
<None Include="Build/IntelliTect.Multitool.targets" Pack="true" PackagePath="build\IntelliTect.Multitool.targets"/>
28+
</ItemGroup>
2629
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Globalization;
2+
using System.Reflection;
3+
4+
namespace IntelliTect.Multitool;
5+
6+
/// <summary>
7+
/// Information about the executing assembly.
8+
/// </summary>
9+
[AttributeUsage(AttributeTargets.Assembly)]
10+
public class ReleaseDateAttribute : Attribute
11+
{
12+
/// <summary>
13+
/// Constructor called from csproj file
14+
/// </summary>
15+
/// <param name="utcDateString">A utc O (round-trip date/time) format string</param>
16+
public ReleaseDateAttribute(string utcDateString)
17+
{
18+
ReleaseDate = DateTime.ParseExact(utcDateString, "O", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
19+
}
20+
/// <summary>
21+
/// The date the assembly was built
22+
/// </summary>
23+
public DateTime ReleaseDate { get; }
24+
/// <summary>
25+
/// Method to obtain the release date from the assembly attributes
26+
/// </summary>
27+
/// <param name="assembly">An assembly instance</param>
28+
/// <returns>The date time from compilation time</returns>
29+
public static DateTime? GetReleaseDate(Assembly? assembly = null)
30+
{
31+
object[]? attribute = (assembly ?? Assembly.GetEntryAssembly())?.GetCustomAttributes(typeof(ReleaseDateAttribute), false);
32+
return attribute?.Length >= 1 ? ((ReleaseDateAttribute)attribute[0]).ReleaseDate : null;
33+
}
34+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
### IntelliTect.Multitool
88

9-
* AssemblyInfo: Gets an assembly's linker date/time as shown in [IntelliTect's Blog](https://intellitect.com/blog/displaying-deploymentbuild-date-web-pages/).
9+
* ReleaseDateAttribute: Gets an UTC DateTime from compile time.
1010
* Example Usage:
1111

1212
```csharp
1313
// This example is in cshtml.
14-
@(AssemblyInfo.Date.ToString("yyyy-MM-dd HH-mm"))
14+
@(ReleaseDateAttribute.GetReleaseDate() // Returns a time in UTC
1515
```
1616

1717
* RepositoryPaths: Provides consistent environment-independent normalized pathing within a repository.

0 commit comments

Comments
 (0)