Skip to content

Commit 9f6517a

Browse files
committed
Fixed issue where building can result in a build performance decrease due to having the build task being inline.
Signed-off-by: AraHaan <seandhunt_7@yahoo.com>
1 parent 891198b commit 9f6517a

11 files changed

+91
-22
lines changed

GitBuildInfo.SourceGenerator.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitBuildInfo.SourceGenerato
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elskom.GitInformation", "src\Elskom.GitInformation\Elskom.GitInformation.csproj", "{FD675B8D-C607-4007-A7E1-09531F535EE6}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitBuildInfo", "src\GitBuildInfo\GitBuildInfo.csproj", "{8204B51B-B642-4DC1-9844-90FF61336C17}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -62,10 +64,23 @@ Global
6264
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|x64.Build.0 = Release|Any CPU
6365
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|x86.ActiveCfg = Release|Any CPU
6466
{FD675B8D-C607-4007-A7E1-09531F535EE6}.Release|x86.Build.0 = Release|Any CPU
67+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
68+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|Any CPU.Build.0 = Debug|Any CPU
69+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x64.ActiveCfg = Debug|Any CPU
70+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x64.Build.0 = Debug|Any CPU
71+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x86.ActiveCfg = Debug|Any CPU
72+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x86.Build.0 = Debug|Any CPU
73+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|Any CPU.ActiveCfg = Release|Any CPU
74+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|Any CPU.Build.0 = Release|Any CPU
75+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x64.ActiveCfg = Release|Any CPU
76+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x64.Build.0 = Release|Any CPU
77+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x86.ActiveCfg = Release|Any CPU
78+
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x86.Build.0 = Release|Any CPU
6579
EndGlobalSection
6680
GlobalSection(NestedProjects) = preSolution
6781
{D769E982-58EE-436B-B2A8-C35D4D55BA8D} = {99761A41-8AED-49B5-AF0F-CF6CCAE482E8}
6882
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9} = {B84AD34C-E5C4-418F-A58A-195C9F89A961}
6983
{FD675B8D-C607-4007-A7E1-09531F535EE6} = {99761A41-8AED-49B5-AF0F-CF6CCAE482E8}
84+
{8204B51B-B642-4DC1-9844-90FF61336C17} = {99761A41-8AED-49B5-AF0F-CF6CCAE482E8}
7085
EndGlobalSection
7186
EndGlobal

build/GitBuildInfo.SourceGenerator.targets

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
<Project>
1+
<Project TreatAsLocalProperty="TaskAssembly">
22

3-
<UsingTask TaskName="GitBuildInfo.GitInfoTask"
4-
TaskFactory="RoslynCodeTaskFactory"
5-
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
6-
<ParameterGroup>
7-
<ProjectDir ParameterType="System.String" Required="true" />
8-
<GitHead ParameterType="System.String" Output="true" />
9-
<CommitHash ParameterType="System.String" Output="true" />
10-
<GitBranch ParameterType="System.String" Output="true" />
11-
</ParameterGroup>
12-
<Task>
13-
<Code Source="$(MSBuildThisFileDirectory)GitInfoTask.cs" />
14-
</Task>
15-
</UsingTask>
3+
<PropertyGroup>
4+
<TaskAssembly>$(MSBuildThisFileDirectory)..\tasks\netstandard2.0\GitBuildInfo.dll</TaskAssembly>
5+
<TaskAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tasks\net472\GitBuildInfo.dll</TaskAssembly>
6+
</PropertyGroup>
7+
8+
<UsingTask TaskName="GitBuildInfo.GitInfoTask" AssemblyFile="$(TaskAssembly)" />
169

1710
<Target Name="GitBuildInfo" AfterTargets="BeforeBuild">
1811
<GitInfoTask ProjectDir="$(MSBuildProjectDirectory)">
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
<Project>
2-
<Import Project="../../build/GitBuildInfo.SourceGenerator.targets" />
2+
3+
<UsingTask TaskName="GitBuildInfo.GitInfoTask"
4+
TaskFactory="RoslynCodeTaskFactory"
5+
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
6+
<ParameterGroup>
7+
<ProjectDir ParameterType="System.String" Required="true" />
8+
<GitHead ParameterType="System.String" Output="true" />
9+
<CommitHash ParameterType="System.String" Output="true" />
10+
<GitBranch ParameterType="System.String" Output="true" />
11+
</ParameterGroup>
12+
<Task>
13+
<Code Source="$(MSBuildThisFileDirectory)../GitBuildInfo/GitInfoTask.cs" />
14+
</Task>
15+
</UsingTask>
16+
17+
<Target Name="GitBuildInfo" AfterTargets="BeforeBuild">
18+
<GitInfoTask ProjectDir="$(MSBuildProjectDirectory)">
19+
<Output TaskParameter="GitHead" PropertyName="GitHead" />
20+
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
21+
<Output TaskParameter="GitBranch" PropertyName="GitBranch" />
22+
</GitInfoTask>
23+
</Target>
24+
325
</Project>

src/GitBuildInfo.SourceGenerator/Directory.Build.props

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<IsPackable>true</IsPackable>
6-
<Version>1.0.12</Version>
7-
<PackageReleaseNotes>Fix bug in build task allowing it to run multiple times when multitargeting and when packing nuget packages.</PackageReleaseNotes>
6+
<Version>1.0.13</Version>
7+
<PackageReleaseNotes>Fixed issue where building can result in a build performance decrease due to having the build task being inline.</PackageReleaseNotes>
88
<Copyright>Copyright (c) 2021</Copyright>
9+
<!-- Suppresses the warnings about the package not having assemblies in lib/*/.dll.-->
10+
<NoPackageAnalysis>true</NoPackageAnalysis>
911
<!-- Special properties for analyzer packages. -->
1012
<IncludeBuildOutput>false</IncludeBuildOutput>
1113
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

src/GitBuildInfo.SourceGenerator/GitBuildInfo.SourceGenerator.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
<file src="$BaseOutputPath$zh-Hant\**" target="analyzers\cs\zh-Hant\" />
3636
<file src="..\..\build\**" target="build\" />
3737
<file src="..\..\tools\**" target="tools\" />
38+
<file src="..\GitBuildInfo\bin\$configuration$\**" target="tasks\" />
3839
</files>
3940
</package>

src/GitBuildInfo.SourceGenerator/GitBuildInfo.SourceGenerator.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuspec">
88
<PropertyGroup>
9-
<NuspecProperties>$(NuspecProperties);Version=$(Version);BaseOutputPath=$(OutputPath);PackageReleaseNotes=$(PackageReleaseNotes);</NuspecProperties>
9+
<NuspecProperties>$(NuspecProperties);Version=$(Version);BaseOutputPath=$(OutputPath);PackageReleaseNotes=$(PackageReleaseNotes);configuration=$(Configuration);</NuspecProperties>
1010
</PropertyGroup>
1111
</Target>
1212

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<CheckEolTargetFramework>false</CheckEolTargetFramework>
5+
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
6+
<!-- We need to pack this up inside of the source generator package. -->
7+
<IsPackable>false</IsPackable>
8+
<Version>0.0.0</Version>
9+
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
10+
<Description>A MSBuild task that generates the git build information.</Description>
11+
</PropertyGroup>
12+
13+
<Import Project="../../Directory.Build.props" />
14+
15+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project>
2+
3+
<ItemGroup>
4+
<PackageReference Include="Microsoft.Build.Framework" Version="*-*" PrivateAssets="All" />
5+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="*-*" PrivateAssets="All" />
6+
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="*-*">
7+
<PrivateAssets>all</PrivateAssets>
8+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9+
</PackageReference>
10+
<PackageReference Include="SecurityCodeScan.VS2019" Version="*-*">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="SonarAnalyzer.CSharp" Version="*-*">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Project Sdk="Microsoft.NET.Sdk" />
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace GitBuildInfo
22
{
3-
using System;
43
using System.ComponentModel;
54
using System.Diagnostics;
6-
using System.IO;
7-
using System.Text;
5+
using System.Diagnostics.CodeAnalysis;
86
using Microsoft.Build.Framework;
97
using Microsoft.Build.Utilities;
108

@@ -13,6 +11,7 @@
1311
///
1412
/// Note: use in the BeforeBuild target.
1513
/// </summary>
14+
[ExcludeFromCodeCoverage]
1615
public class GitInfoTask : Task
1716
{
1817
/// <summary>
@@ -55,7 +54,7 @@ public override bool Execute()
5554
this.CommitHash = this.RunGit("rev-parse --short HEAD");
5655
this.GitBranch = this.RunGit("name-rev --name-only HEAD");
5756
this.Log.LogMessage(MessageImportance.High, "Getting build info from git");
58-
cache = new GitInfo()
57+
cache = new GitInfo
5958
{
6059
Head = this.GitHead,
6160
CommitHash = this.CommitHash,

0 commit comments

Comments
 (0)