Skip to content

Commit b21e6e9

Browse files
authored
Merge pull request #94 from cake-contrib/feature/GH-76
(GH-76) added net5.0 as suggested for Cake 1.0.0
2 parents 8cba2d2 + 558b4f7 commit b21e6e9

File tree

12 files changed

+309
-119
lines changed

12 files changed

+309
-119
lines changed

docs/input/guidelines/TargetFramework.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@ Title: Target Frameworks
1818

1919
## Goals
2020

21-
As .NET Framework < 4.7.2 has issues with running .NET Standard assemblies, and Cake itself can run on .NET Framework 4.6.1 it is suggested to multi-target addins to `netstandard2.0` and `net461` to have the maximum compatibility.
21+
Each addin should have maximum compatibility when being used. Toward that end some Framework versions are required and some others are
22+
suggested, depending on the Cake.Core version that is being referenced.
2223

2324
### Required / Suggested versions
2425

2526
Depending on the referenced `Cake.Core`-version different target versions are required and/or suggested.
2627
Missing a required target version will raise [CCG0007](../rules/ccg0007) as an error
2728
while missing a suggested target version will raise [CCG0007](../rules/ccg0007) as a warning.
2829

29-
* Cake.Core <= 0.33.0
30+
* Cake.Core < 1.0.0
3031
* Required: `netstandard2.0`
3132
* Suggested: `net461`
3233
* alternative: `net46`
34+
* Cake.Core >= 1.0.0
35+
* Required: `netstandard2.0`
36+
* Suggested: `net461`
37+
* alternative: `net46`
38+
* Suggested: `net5.0`
3339

3440
## Related rules
3541

docs/input/rules/ccg0007.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ Also, This could be raised as an error, if a required target version is not set.
2424

2525
## Description
2626

27-
Addins should be multi-targeted to `netstandard2.0` and `net461` to have the maximum compatibility.
27+
Addins should be multi-targeted to different framework versions to have the maximum compatibility.
2828

2929
## How to fix violations
3030

31-
Add the recommended target(s) to the project:
31+
Add the recommended target(s) to the project (example for an addin referencing Cake.Core 1.0.0):
3232

3333
```xml
3434
<PropertyGroup>
35-
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
35+
<TargetFrameworks>netstandard2.0;net461;net5.0</TargetFrameworks>
3636
</PropertyGroup>
3737
```
3838

src/Guidelines/build/TargetFrameworkVersions.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<!-- All other rules have some "configuration" here, this rules required/suggested targets are hard-coded in the task. Sadly. -->
1313

1414
<TargetFrameworkVersions
15-
References="@(Reference)"
15+
References="@(PackageReference)"
1616
TargetFramework="$(TargetFramework)"
1717
TargetFrameworks="$(TargetFrameworks)"
1818
Omitted="@(CakeContribGuidelinesOmitTargetFramework)"

src/Tasks.IntegrationTests/E2eTests.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,7 @@ public void PackageIcon_Tag_with_modified_CakeContribGuidelinesIconDestinationLo
103103
public void Referencing_Cake_Core_with_PrivateAssets_results_in_no_error()
104104
{
105105
// given
106-
fixture.WithCustomContent($@"
107-
<ItemGroup>
108-
<PackageReference Include=""Cake.Core"" Version=""0.38.5"" PrivateAssets=""all"" />
109-
</ItemGroup>");
106+
fixture.WithPackageReference("Cake.Core", "0.38.5", "all");
110107

111108
// when
112109
var result = fixture.Run();
@@ -120,10 +117,7 @@ public void Referencing_Cake_Core_with_PrivateAssets_results_in_no_error()
120117
public void Referencing_Cake_Core_without_PrivateAssets_results_in_CCG0004_error()
121118
{
122119
// given
123-
fixture.WithCustomContent($@"
124-
<ItemGroup>
125-
<PackageReference Include=""Cake.Core"" Version=""0.38.5"" />
126-
</ItemGroup>");
120+
fixture.WithPackageReference("Cake.Core", "0.38.5");
127121

128122
// when
129123
var result = fixture.Run();
@@ -224,5 +218,36 @@ public void Missing_Suggested_Target_results_in_CCG0007_warning()
224218
result.WarningLines.Should().Contain(l => l.IndexOf("CCG0007", StringComparison.Ordinal) > -1);
225219
result.WarningLines.Should().Contain(l => l.IndexOf("net461", StringComparison.Ordinal) > -1);
226220
}
221+
222+
[Fact]
223+
public void Missing_Suggested_Target_net5_for_Cake_v100_results_in_CCG0007_warning()
224+
{
225+
// given
226+
fixture.WithPackageReference("Cake.Core", "1.0.0", "all");
227+
fixture.WithTargetFrameworks("netstandard2.0;net461");
228+
229+
// when
230+
var result = fixture.Run();
231+
232+
// then
233+
result.IsErrorExitCode.Should().BeFalse();
234+
result.WarningLines.Should().Contain(l => l.IndexOf("CCG0007", StringComparison.Ordinal) > -1);
235+
result.WarningLines.Should().Contain(l => l.IndexOf("net5.0", StringComparison.Ordinal) > -1);
236+
}
237+
238+
[Fact]
239+
public void Referencing_CakeCore_With_all_targets_raises_no_warning()
240+
{
241+
// given
242+
fixture.WithPackageReference("Cake.Core", "1.0.0", "all");
243+
fixture.WithTargetFrameworks("netstandard2.0;net461;net5.0");
244+
245+
// when
246+
var result = fixture.Run();
247+
248+
// then
249+
result.IsErrorExitCode.Should().BeFalse();
250+
result.WarningLines.Should().BeEmpty();
251+
}
227252
}
228253
}

src/Tasks.IntegrationTests/Fixtures/E2eTestFixture.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
using System.Text;
67

78
using Xunit.Abstractions;
89

@@ -20,6 +21,7 @@ public class E2eTestFixture : IDisposable
2021
private bool hasEditorConfig = true;
2122
private readonly List<string> customContent = new List<string>();
2223
private string targetFrameworks = "netstandard2.0;net461";
24+
private readonly List<string> references = new List<string>();
2325

2426
public E2eTestFixture(string tempFolder, ITestOutputHelper logger)
2527
{
@@ -90,6 +92,7 @@ private string WriteProject()
9092
<PrivateAssets>all</PrivateAssets>
9193
</PackageReference>");
9294
}
95+
items.AddRange(references);
9396

9497
File.WriteAllText(csproj, string.Format(template,
9598
targets.Item1,
@@ -122,6 +125,28 @@ internal void WithCustomContent(string content)
122125
customContent.Add(content);
123126
}
124127

128+
internal void WithPackageReference(
129+
string packageName,
130+
string version,
131+
string privateAssets = null,
132+
params Tuple<string, string>[] additionalAttributes)
133+
{
134+
var reference = new StringBuilder();
135+
reference.Append($@"<PackageReference Include=""{packageName}"" Version=""{version}""");
136+
if (privateAssets != null)
137+
{
138+
reference.Append($@" PrivateAssets=""{privateAssets}""");
139+
}
140+
141+
foreach ((string key, string val) in additionalAttributes)
142+
{
143+
reference.Append($@" {key}=""{val}""");
144+
}
145+
146+
reference.Append(" />");
147+
references.Add(reference.ToString());
148+
}
149+
125150
internal void WithoutStylecopReference()
126151
{
127152
hasStylecopReference = false;
Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23

34
using CakeContrib.Guidelines.Tasks.Extensions;
45

@@ -10,58 +11,60 @@ namespace CakeContrib.Guidelines.Tasks.Tests.Extensions
1011
{
1112
public class VersionExtensionTests
1213
{
13-
[Fact]
14-
public void GreaterEqual_Is_True_For_Equal_Versions()
14+
[Theory]
15+
[MemberData(nameof(GetGreaterEqualData))]
16+
public void GreaterEqualTheory(Version lhs, Version rhs, bool expected)
1517
{
16-
var a = new Version(1, 2, 3);
17-
var b = new Version(a.Major, a.Minor, a.Build);
18-
19-
a.GreaterEqual(b).Should().BeTrue();
18+
lhs.GreaterEqual(rhs).Should().Be(expected);
2019
}
2120

22-
[Fact]
23-
public void GreaterEqual_Is_True_For_Greater_Versions()
21+
public static IEnumerable<object[]> GetGreaterEqualData()
2422
{
25-
var a = new Version(1, 2, 3);
26-
var b = new Version(a.Major, a.Minor, a.Build - 1);
27-
28-
a.GreaterEqual(b).Should().BeTrue();
23+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 3), true };
24+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 2), true };
25+
yield return new object[] { new Version(1, 2, 2), new Version(1, 2, 3), false };
2926
}
3027

31-
[Fact]
32-
public void GreaterEqual_Is_False_For_Lesser_Versions()
28+
[Theory]
29+
[MemberData(nameof(GetLessEqualData))]
30+
public void LessEqualTheory(Version lhs, Version rhs, bool expected)
3331
{
34-
var a = new Version(1, 2, 3);
35-
var b = new Version(a.Major, a.Minor, a.Build + 1);
36-
37-
a.GreaterEqual(b).Should().BeFalse();
32+
lhs.LessEqual(rhs).Should().Be(expected);
3833
}
3934

40-
[Fact]
41-
public void LessEqual_Is_True_For_Equal_Versions()
35+
public static IEnumerable<object[]> GetLessEqualData()
4236
{
43-
var a = new Version(1, 2, 3);
44-
var b = new Version(a.Major, a.Minor, a.Build);
45-
46-
a.LessEqual(b).Should().BeTrue();
37+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 3), true };
38+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 2), false };
39+
yield return new object[] { new Version(1, 2, 2), new Version(1, 2, 3), true };
4740
}
4841

49-
[Fact]
50-
public void LessEqual_Is_True_For_Lesser_Versions()
42+
[Theory]
43+
[MemberData(nameof(GetGreaterThanData))]
44+
public void GreaterThanTheory(Version lhs, Version rhs, bool expected)
5145
{
52-
var a = new Version(1, 2, 3);
53-
var b = new Version(a.Major, a.Minor, a.Build + 1);
46+
lhs.GreaterThan(rhs).Should().Be(expected);
47+
}
5448

55-
a.LessEqual(b).Should().BeTrue();
49+
public static IEnumerable<object[]> GetGreaterThanData()
50+
{
51+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 3), false };
52+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 2), true };
53+
yield return new object[] { new Version(1, 2, 2), new Version(1, 2, 3), false };
5654
}
5755

58-
[Fact]
59-
public void LessEqual_Is_False_For_Greater_Versions()
56+
[Theory]
57+
[MemberData(nameof(GetLessThanData))]
58+
public void LessThanTheory(Version lhs, Version rhs, bool expected)
6059
{
61-
var a = new Version(1, 2, 3);
62-
var b = new Version(a.Major, a.Minor, a.Build - 1);
60+
lhs.LessThan(rhs).Should().Be(expected);
61+
}
6362

64-
a.LessEqual(b).Should().BeFalse();
63+
public static IEnumerable<object[]> GetLessThanData()
64+
{
65+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 3), false };
66+
yield return new object[] { new Version(1, 2, 3), new Version(1, 2, 2), false };
67+
yield return new object[] { new Version(1, 2, 2), new Version(1, 2, 3), true };
6568
}
6669
}
6770
}

src/Tasks.Tests/Fixtures/RequiredReferencesFixture.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23

34
using Microsoft.Build.Framework;
@@ -50,7 +51,9 @@ public void WithReferencedPackage(string packageName, string privateAssets = "")
5051
{
5152
var referencedPackage = new Mock<ITaskItem>();
5253
referencedPackage.Setup(x => x.ToString()).Returns(packageName);
53-
referencedPackage.Setup(x => x.GetMetadata("PrivateAssets")).Returns(privateAssets);
54+
referencedPackage.Setup(x => x.GetMetadata(
55+
It.Is<string>(y => "PrivateAssets".Equals(y, StringComparison.OrdinalIgnoreCase))))
56+
.Returns(privateAssets);
5457
references.Add(referencedPackage.Object);
5558
}
5659
}

src/Tasks.Tests/Fixtures/TargetFrameworkVersionsFixture.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Linq;
34

@@ -31,25 +32,27 @@ public override bool Execute()
3132
return base.Execute();
3233
}
3334

34-
public void WithTargetFramwork(string packageName)
35+
public void WithTargetFramework(string packageName)
3536
{
3637
targetFramework = GetMockTaskItem(packageName).Object;
3738
}
3839

39-
public void WithTargetFramworks(params string[] packageNames)
40+
public void WithTargetFrameworks(params string[] packageNames)
4041
{
4142
targetFrameworks.AddRange(packageNames.Select(n => GetMockTaskItem(n).Object));
4243
}
4344

44-
public void WithOmittedTargetFramework(string targetFramework)
45+
public void WithOmittedTargetFramework(string targetFrameworkToOmit)
4546
{
46-
omittedTargets.Add(GetMockTaskItem(targetFramework).Object);
47+
omittedTargets.Add(GetMockTaskItem(targetFrameworkToOmit).Object);
4748
}
4849

4950
public void WithCakeCoreReference(int major = 0, int minor = 0, int patch = 0)
5051
{
5152
var cakeRef = GetMockTaskItem("Cake.Core");
52-
cakeRef.Setup(x => x.GetMetadata("Version")).Returns($"{major}.{minor}.{patch}");
53+
cakeRef.Setup(x => x.GetMetadata(
54+
It.Is<string>(y => "version".Equals(y, StringComparison.OrdinalIgnoreCase))))
55+
.Returns($"{major}.{minor}.{patch}");
5356
references.Add(cakeRef.Object);
5457
}
5558

0 commit comments

Comments
 (0)