Skip to content

Commit 0e924ff

Browse files
committed
[new-cli] switched Generator to netstandard2.0, added polyfills
1 parent cbb3f77 commit 0e924ff

14 files changed

+220
-16
lines changed

new-cli/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
2222
<PackageVersion Include="Serilog.Sinks.Map" Version="2.0.0" />
2323
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.24324.3" />
24+
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
2425
</ItemGroup>
2526
</Project>

new-cli/GitVersion.Cli.Generator/CommandImplGenerator.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using System.Collections.Immutable;
2-
using Microsoft.CodeAnalysis;
3-
using Scriban;
1+
using GitVersion.Polyfill;
2+
43
// ReSharper disable InconsistentNaming
54
namespace GitVersion;
65

@@ -88,11 +87,11 @@ private static void GenerateSourceCode(SourceProductionContext context, Immutabl
8887
var name = Convert.ToString(ctorArguments[0].Value);
8988
var description = Convert.ToString(ctorArguments[1].Value);
9089

91-
ArgumentNullException.ThrowIfNull(name);
92-
ArgumentNullException.ThrowIfNull(description);
90+
name.NotNull();
91+
description.NotNull();
9392

9493
ITypeSymbol? parentCommandType = null;
95-
if (commandAttribute.AttributeClass != null && commandAttribute.AttributeClass.TypeArguments.Any())
94+
if (commandAttribute.AttributeClass?.TypeArguments.Any() == true)
9695
{
9796
parentCommandType = commandAttribute.AttributeClass.TypeArguments.Single();
9897
}
@@ -130,8 +129,8 @@ private static SettingsPropertyInfo MapToPropertyInfo(IPropertySymbol propertySy
130129
var name = Convert.ToString(ctorArguments[0].Value);
131130
var description = Convert.ToString(ctorArguments[1].Value);
132131

133-
ArgumentNullException.ThrowIfNull(name);
134-
ArgumentNullException.ThrowIfNull(description);
132+
name.NotNull();
133+
description.NotNull();
135134

136135
string alias = string.Empty;
137136
if (ctorArguments.Length == 3)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
45
<IsRoslynComponent>true</IsRoslynComponent>
56
<PackageScribanIncludeSource>true</PackageScribanIncludeSource>
67
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
78
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
8-
<NoWarn>$(NoWarn);RS1035;CS8669</NoWarn>
99
</PropertyGroup>
1010

1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.CSharp" />
1313
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
1414
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
1515
<PackageReference Include="Scriban" IncludeAssets="Build" />
16+
<PackageReference Include="System.Text.Json" />
1617
</ItemGroup>
1718
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
global using System.Collections.Immutable;
2+
global using System.Diagnostics.CodeAnalysis;
3+
global using System.Runtime.CompilerServices;
4+
global using Microsoft.CodeAnalysis;
5+
global using Scriban;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// <auto-generated />
2+
#pragma warning disable
3+
4+
#if NETFRAMEWORK || NETSTANDARD || NETCOREAPP2X
5+
6+
namespace System.Runtime.CompilerServices;
7+
8+
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
10+
using Link = System.ComponentModel.DescriptionAttribute;
11+
12+
/// <summary>
13+
/// Indicates that a parameter captures the expression passed for another parameter as a string.
14+
/// </summary>
15+
[ExcludeFromCodeCoverage]
16+
[DebuggerNonUserCode]
17+
[AttributeUsage(AttributeTargets.Parameter)]
18+
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callerargumentexpressionattribute")]
19+
#if PolyPublic
20+
public
21+
#endif
22+
sealed class CallerArgumentExpressionAttribute :
23+
Attribute
24+
{
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="CallerArgumentExpressionAttribute"/> class.
27+
/// </summary>
28+
/// <param name="parameterName">
29+
/// The name of the parameter whose expression should be captured as a string.
30+
/// </param>
31+
public CallerArgumentExpressionAttribute(string parameterName) =>
32+
ParameterName = parameterName;
33+
34+
/// <summary>
35+
/// Gets the name of the parameter whose expression should be captured as a string.
36+
/// </summary>
37+
public string ParameterName { get; }
38+
}
39+
40+
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace GitVersion.Polyfill;
2+
3+
public static class CommonExtensions
4+
{
5+
public static T NotNull<T>([NotNull] this T? value, [CallerArgumentExpression(nameof(value))] string name = "")
6+
where T : class => value ?? throw new ArgumentNullException(name);
7+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// <auto-generated />
2+
#pragma warning disable
3+
4+
#if !NET7_0_OR_GREATER
5+
6+
namespace System.Runtime.CompilerServices;
7+
8+
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
10+
using Link = System.ComponentModel.DescriptionAttribute;
11+
12+
/// <summary>
13+
/// Indicates that compiler support for a particular feature is required for the location where this attribute is applied.
14+
/// </summary>
15+
[ExcludeFromCodeCoverage]
16+
[DebuggerNonUserCode]
17+
[AttributeUsage(
18+
validOn: AttributeTargets.All,
19+
AllowMultiple = true,
20+
Inherited = false)]
21+
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.compilerfeaturerequiredattribute")]
22+
#if PolyPublic
23+
public
24+
#endif
25+
sealed class CompilerFeatureRequiredAttribute :
26+
Attribute
27+
{
28+
/// <summary>
29+
/// Initialize a new instance of <see cref="CompilerFeatureRequiredAttribute"/>
30+
/// </summary>
31+
/// <param name="featureName">The name of the required compiler feature.</param>
32+
public CompilerFeatureRequiredAttribute(string featureName) =>
33+
FeatureName = featureName;
34+
35+
/// <summary>
36+
/// The name of the compiler feature.
37+
/// </summary>
38+
public string FeatureName { get; }
39+
40+
/// <summary>
41+
/// If true, the compiler can choose to allow access to the location where this attribute is applied if it does not understand <see cref="FeatureName"/>.
42+
/// </summary>
43+
public bool IsOptional { get; init; }
44+
45+
/// <summary>
46+
/// The <see cref="FeatureName"/> used for the ref structs C# feature.
47+
/// </summary>
48+
public const string RefStructs = nameof(RefStructs);
49+
50+
/// <summary>
51+
/// The <see cref="FeatureName"/> used for the required members C# feature.
52+
/// </summary>
53+
public const string RequiredMembers = nameof(RequiredMembers);
54+
}
55+
56+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// <auto-generated />
2+
#pragma warning disable
3+
4+
#if !NET5_0_OR_GREATER
5+
6+
namespace System.Runtime.CompilerServices;
7+
8+
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
10+
11+
/// <summary>
12+
/// Reserved to be used by the compiler for tracking metadata. This class should not be used by developers in source code.
13+
/// </summary>
14+
[ExcludeFromCodeCoverage]
15+
[DebuggerNonUserCode]
16+
#if PolyPublic
17+
public
18+
#endif
19+
static class IsExternalInit;
20+
21+
#endif
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// <auto-generated />
2+
#pragma warning disable
3+
4+
#if NETSTANDARD2_0 || NETFRAMEWORK || NETCOREAPP2X
5+
6+
namespace System.Diagnostics.CodeAnalysis;
7+
8+
using Targets = AttributeTargets;
9+
10+
/// <summary>
11+
/// Specifies that an output is not <see langword="null"/> even if the
12+
/// corresponding type allows it.
13+
/// </summary>
14+
[ExcludeFromCodeCoverage]
15+
[DebuggerNonUserCode]
16+
[AttributeUsage(
17+
validOn: Targets.Field |
18+
Targets.Parameter |
19+
Targets.Property |
20+
Targets.ReturnValue)]
21+
#if PolyPublic
22+
public
23+
#endif
24+
sealed class NotNullAttribute :
25+
Attribute;
26+
#endif
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// <auto-generated />
2+
#pragma warning disable
3+
4+
#if !NET7_0_OR_GREATER
5+
6+
namespace System.Runtime.CompilerServices;
7+
8+
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
10+
11+
using Targets = AttributeTargets;
12+
13+
/// <summary>
14+
/// Specifies that a type has required members or that a member is required.
15+
/// </summary>
16+
[ExcludeFromCodeCoverage]
17+
[DebuggerNonUserCode]
18+
[AttributeUsage(
19+
validOn: Targets.Class |
20+
Targets.Struct |
21+
Targets.Field |
22+
Targets.Property,
23+
Inherited = false)]
24+
#if PolyPublic
25+
public
26+
#endif
27+
sealed class RequiredMemberAttribute :
28+
Attribute;
29+
#endif

0 commit comments

Comments
 (0)