Skip to content

Commit bf0ee0f

Browse files
committed
Removed MSBuild task assembly and replaced them when msbuild execute commands to grab the needed data and output them to intermediate files for the generator to use.
Signed-off-by: AraHaan <seandhunt_7@yahoo.com>
1 parent e804224 commit bf0ee0f

16 files changed

+123
-212
lines changed

.github/workflows/codacy-analysis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030

3131
- name: Install latest .NET SDK
3232
uses: Elskom/setup-latest-dotnet@main
33+
with:
34+
VERSION_MAJOR: '6'
35+
VERSION_BAND: '2xx'
3336

3437
- name: Restore, Build, and test
3538
uses: Elskom/build-dotnet@main

.github/workflows/dotnetcore-build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717

1818
- name: Install latest .NET SDK
1919
uses: Elskom/setup-latest-dotnet@main
20+
with:
21+
VERSION_MAJOR: '6'
22+
VERSION_BAND: '2xx'
2023

2124
- name: Restore, Build, test, and pack
2225
uses: Elskom/build-dotnet@main

.github/workflows/dotnetcore-publish.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919

2020
- name: Install latest .NET SDK
2121
uses: Elskom/setup-latest-dotnet@main
22+
with:
23+
VERSION_MAJOR: '6'
24+
VERSION_BAND: '2xx'
2225

2326
- name: Restore, Build, test, and pack
2427
uses: Elskom/build-dotnet@main

.github/workflows/dotnetcore.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ jobs:
1111
DOTNET_NOLOGO: true
1212
steps:
1313
- uses: actions/checkout@main
14-
- name: .NET core build
15-
uses: actions/setup-dotnet@main
14+
15+
- name: Install latest .NET SDK
16+
uses: Elskom/setup-latest-dotnet@main
1617
with:
17-
dotnet-version: '6.0.x'
18-
include-prerelease: true
18+
VERSION_MAJOR: '6'
19+
VERSION_BAND: '2xx'
1920

2021
- name: Restore, Build, test, and pack
2122
uses: Elskom/build-dotnet@main
2223
with:
23-
SOLUTION_FILE_PATH: GitBuildInfo.SourceGenerator.sln
2424
TEST: true

GitBuildInfo.SourceGenerator.sln

-15
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B84AD34C
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitBuildInfo.SourceGenerator.Tests", "tests/GitBuildInfo.SourceGenerator.Tests.csproj", "{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}"
1313
EndProject
14-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitBuildInfo", "src\GitBuildInfo\GitBuildInfo.csproj", "{8204B51B-B642-4DC1-9844-90FF61336C17}"
15-
EndProject
1614
Global
1715
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1816
Debug|Any CPU = Debug|Any CPU
@@ -50,22 +48,9 @@ Global
5048
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}.Release|x64.Build.0 = Release|Any CPU
5149
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}.Release|x86.ActiveCfg = Release|Any CPU
5250
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9}.Release|x86.Build.0 = Release|Any CPU
53-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|Any CPU.Build.0 = Debug|Any CPU
55-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x64.ActiveCfg = Debug|Any CPU
56-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x64.Build.0 = Debug|Any CPU
57-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x86.ActiveCfg = Debug|Any CPU
58-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Debug|x86.Build.0 = Debug|Any CPU
59-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|Any CPU.ActiveCfg = Release|Any CPU
60-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|Any CPU.Build.0 = Release|Any CPU
61-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x64.ActiveCfg = Release|Any CPU
62-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x64.Build.0 = Release|Any CPU
63-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x86.ActiveCfg = Release|Any CPU
64-
{8204B51B-B642-4DC1-9844-90FF61336C17}.Release|x86.Build.0 = Release|Any CPU
6551
EndGlobalSection
6652
GlobalSection(NestedProjects) = preSolution
6753
{D769E982-58EE-436B-B2A8-C35D4D55BA8D} = {99761A41-8AED-49B5-AF0F-CF6CCAE482E8}
6854
{5A9FCC65-752B-499B-A86B-ABCC6F4666D9} = {B84AD34C-E5C4-418F-A58A-195C9F89A961}
69-
{8204B51B-B642-4DC1-9844-90FF61336C17} = {99761A41-8AED-49B5-AF0F-CF6CCAE482E8}
7055
EndGlobalSection
7156
EndGlobal

build/GitBuildInfo.SourceGenerator.props

-17
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,4 @@
44
<GitBuildInfoIsGeneric Condition="'$(GitBuildInfoIsGeneric)' == ''">false</GitBuildInfoIsGeneric>
55
</PropertyGroup>
66

7-
<ItemGroup>
8-
<!--
9-
Add the namespace for the generated attribute to the global usings list only if the C# language version is 10.0 or newer.
10-
-->
11-
<Using Include="Elskom.Generic.Libs" Condition="'$(ImplicitUsings)' == 'enable'" />
12-
<!--
13-
Add the root namespace to the global usings list only if the C# language version is 10.0 or newer.
14-
-->
15-
<Using Include="$(RootNamespace)" Condition="'$(ImplicitUsings)' == 'enable'" />
16-
<CompilerVisibleProperty Include="RootNamespace" />
17-
<CompilerVisibleProperty Include="GitBuildInfoAssemblyType" />
18-
<CompilerVisibleProperty Include="GitBuildInfoIsGeneric" />
19-
<CompilerVisibleProperty Include="GitHead" />
20-
<CompilerVisibleProperty Include="CommitHash" />
21-
<CompilerVisibleProperty Include="GitBranch" />
22-
</ItemGroup>
23-
247
</Project>
+89-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,89 @@
1-
<Project TreatAsLocalProperty="TaskAssembly">
2-
3-
<PropertyGroup>
4-
<TaskAssembly>$(MSBuildThisFileDirectory)..\tasks\netstandard2.0\GitBuildInfo.dll</TaskAssembly>
5-
</PropertyGroup>
6-
7-
<UsingTask TaskName="GitBuildInfo.GitInfoTask" AssemblyFile="$(TaskAssembly)" />
8-
9-
<Target Name="GitBuildInfo" AfterTargets="BeforeBuild">
10-
<GitInfoTask ProjectDir="$(MSBuildProjectDirectory)">
11-
<Output TaskParameter="GitHead" PropertyName="GitHead" />
12-
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
13-
<Output TaskParameter="GitBranch" PropertyName="GitBranch" />
14-
</GitInfoTask>
15-
</Target>
16-
17-
</Project>
1+
<Project TreatAsLocalProperty="GitHead;CommitHash;GitBranch">
2+
3+
<Target Name="GitBuildInfo" AfterTargets="BeforeBuild">
4+
<Message
5+
Importance="high"
6+
Text="Getting build info from git"
7+
Condition="'$(GitHead)' == '' AND '$(CommitHash)' == '' AND '$(GitBranch)' == ''" />
8+
<Exec
9+
Command="git describe --all --always --dirty"
10+
WorkingDirectory="$(MSBuildProjectDirectory)"
11+
ConsoleToMSBuild="true"
12+
IgnoreExitCode="true"
13+
Condition="'$(GitHead)' == ''">
14+
<Output TaskParameter="ConsoleOutput" PropertyName="GitHead" />
15+
</Exec>
16+
<Exec
17+
Command="git rev-parse --short HEAD"
18+
WorkingDirectory="$(MSBuildProjectDirectory)"
19+
ConsoleToMSBuild="true"
20+
IgnoreExitCode="true"
21+
Condition="'$(GitHead)' == ''">
22+
<Output TaskParameter="ConsoleOutput" PropertyName="CommitHash" />
23+
</Exec>
24+
<Exec
25+
Command="git name-rev --name-only HEAD"
26+
WorkingDirectory="$(MSBuildProjectDirectory)"
27+
ConsoleToMSBuild="true"
28+
IgnoreExitCode="true"
29+
Condition="'$(GitHead)' == ''">
30+
<Output TaskParameter="ConsoleOutput" PropertyName="GitBranch" />
31+
</Exec>
32+
<WriteLinesToFile
33+
File="$(IntermediateOutputPath)\githead.txt"
34+
Lines="$(GitHead)"
35+
Condition="'$(GitHead)' != ''"
36+
Overwrite="true"
37+
WriteOnlyWhenDifferent="true" />
38+
<WriteLinesToFile
39+
File="$(IntermediateOutputPath)\git_head.txt"
40+
Lines="Not a git clone or git is not in Path."
41+
Condition="'$(GitHead)' == ''"
42+
Overwrite="true"
43+
WriteOnlyWhenDifferent="true" />
44+
<WriteLinesToFile
45+
File="$(IntermediateOutputPath)\git_commit_hash.txt"
46+
Lines="$(CommitHash)"
47+
Condition="'$(CommitHash)' != ''"
48+
Overwrite="true"
49+
WriteOnlyWhenDifferent="true" />
50+
<WriteLinesToFile
51+
File="$(IntermediateOutputPath)\git_commit_hash.txt"
52+
Lines="Not a git clone or git is not in Path."
53+
Condition="'$(CommitHash)' == ''"
54+
Overwrite="true"
55+
WriteOnlyWhenDifferent="true" />
56+
<WriteLinesToFile
57+
File="$(IntermediateOutputPath)\git_branch.txt"
58+
Lines="$(GitBranch)"
59+
Condition="'$(GitBranch)' != ''"
60+
Overwrite="true"
61+
WriteOnlyWhenDifferent="true" />
62+
<WriteLinesToFile
63+
File="$(IntermediateOutputPath)\git_branch.txt"
64+
Lines="Not a git clone or git is not in Path."
65+
Condition="'$(GitBranch)' == ''"
66+
Overwrite="true"
67+
WriteOnlyWhenDifferent="true" />
68+
</Target>
69+
70+
<ItemGroup>
71+
<!--
72+
Add the namespace for the generated attribute to the global usings list only if the C# language version is 10.0 or newer.
73+
-->
74+
<Using Include="Elskom.Generic.Libs" Condition="'$(ImplicitUsings)' == 'enable'" />
75+
<!--
76+
Add the root namespace to the global usings list only if the C# language version is 10.0 or newer.
77+
78+
Also avoid trying to add Elskom.Generic.Libs twice when RootNamespace is that value.
79+
-->
80+
<Using Include="$(RootNamespace)" Condition="'$(ImplicitUsings)' == 'enable' AND '$(RootNamespace)' != 'Elskom.Generic.Libs'" />
81+
<CompilerVisibleProperty Include="RootNamespace" />
82+
<CompilerVisibleProperty Include="GitBuildInfoAssemblyType" />
83+
<CompilerVisibleProperty Include="GitBuildInfoIsGeneric" />
84+
<AdditionalFiles Include="$(IntermediateOutputPath)\git_head.txt" />
85+
<AdditionalFiles Include="$(IntermediateOutputPath)\git_commit_hash.txt" />
86+
<AdditionalFiles Include="$(IntermediateOutputPath)\git_branch.txt" />
87+
</ItemGroup>
88+
89+
</Project>

src/GitBuildInfo.SourceGenerator/Directory.Build.props

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<IsPackable>true</IsPackable>
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.
8-
Also made build task target .NET Standard 2.0 only.
9-
I think this one should work for everyone even for those using .NET Framework's msbuild.
10-
Also the generator now requires setting the RootNamespace msbuild property that holds the type they specifiy in the GitBuildInfoAssemblyType msbuild property.</PackageReleaseNotes>
6+
<Version>1.0.14</Version>
7+
<PackageReleaseNotes>
8+
Removed MSBuild task assembly and replaced them when msbuild execute commands to grab the needed data and output them to intermediate files for the generator to use.
9+
</PackageReleaseNotes>
1110
<Copyright>Copyright (c) 2021</Copyright>
1211
<!-- Suppresses the warnings about the package not having assemblies in lib/*/.dll.-->
1312
<NoPackageAnalysis>true</NoPackageAnalysis>

src/GitBuildInfo.SourceGenerator/GitBuildInfo.SourceGenerator.nuspec

-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@
2121
<file src="$BaseOutputPath$**" target="analyzers\cs\" />
2222
<file src="..\..\build\**" target="build\" />
2323
<file src="..\..\tools\**" target="tools\" />
24-
<file src="..\GitBuildInfo\bin\$configuration$\**" target="tasks\" />
2524
</files>
2625
</package>

src/GitBuildInfo.SourceGenerator/SourceGenerator.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Text;
5+
using System.Linq;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.CSharp;
78
using Microsoft.CodeAnalysis.Text;
@@ -29,9 +30,9 @@ public void Execute(GeneratorExecutionContext context)
2930
_ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.RootNamespace", out var rootNamespace);
3031
_ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.GitBuildInfoAssemblyType", out var assemblyType);
3132
_ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.GitBuildInfoIsGeneric", out var isGeneric);
32-
_ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.GitHead", out var gitHead);
33-
_ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CommitHash", out var commitHash);
34-
_ = context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.GitBranch", out var gitBranch);
33+
var gitHead = context.AdditionalFiles.First(text => text.Path.EndsWith("git_head.txt")).GetText()?.ToString();
34+
var commitHash = context.AdditionalFiles.First(text => text.Path.EndsWith("git_commit_hash.txt")).GetText()?.ToString();
35+
var gitBranch = context.AdditionalFiles.First(text => text.Path.EndsWith("git_branch.txt")).GetText()?.ToString();
3536
context.AddSource(
3637
"GitAssemblyInfo.g.cs",
3738
SourceText.From(
@@ -45,7 +46,12 @@ public void Execute(GeneratorExecutionContext context)
4546
or LanguageVersion.Latest
4647
or LanguageVersion.Preview,
4748
},
48-
new GitInfo { GitHead = gitHead, CommitHash = commitHash, GitBranch = gitBranch },
49+
new GitInfo
50+
{
51+
GitHead = gitHead!.Trim(Environment.NewLine.ToCharArray()),
52+
CommitHash = commitHash!.Trim(Environment.NewLine.ToCharArray()),
53+
GitBranch = gitBranch!.Trim(Environment.NewLine.ToCharArray()),
54+
},
4955
context),
5056
Encoding.UTF8));
5157
}

src/GitBuildInfo/Directory.Build.props

-21
This file was deleted.

src/GitBuildInfo/Directory.Packages.props

-20
This file was deleted.

src/GitBuildInfo/GitBuildInfo.csproj

-1
This file was deleted.

0 commit comments

Comments
 (0)