Skip to content

Commit 9cc18ec

Browse files
authored
Merge pull request #102 from cake-contrib/feature/GH-99
(GH-99) modified CCG0007
2 parents a3fa13f + acdeb4e commit 9cc18ec

File tree

12 files changed

+116
-51
lines changed

12 files changed

+116
-51
lines changed

docs/input/guidelines/RecommendedReferences.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Title: Recommended References
1717

1818
## Goals
1919

20-
To have consistency in code-style among the different tools/plugins the use of Analysers is recommended, especially the use of [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). Additionally code-style anlysis using StyleCopy (and code generation in the IDE) should be properly configured using a `stylecop.json`-file as well as `.editorconfig`-file, respectively.
20+
To have consistency in code-style among the different tools/plugins the use of Analysers is recommended, especially the use of [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). Additionally code-style analysis using StyleCopy (and code generation in the IDE) should be properly configured using a `stylecop.json`-file as well as `.editorconfig`-file, respectively.
2121

2222
Example-Files can be found at:
2323

docs/input/guidelines/TargetFramework.md

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

1919
## Goals
2020

21-
Each addin should have maximum compatibility when being used. Toward that end some Framework versions are required and some others are
21+
Each addin/module should have maximum compatibility when being used. Toward that end some Framework versions are required and some others are
2222
suggested, depending on the Cake.Core version that is being referenced.
2323

2424
### Required / Suggested versions
2525

26-
Depending on the referenced `Cake.Core`-version different target versions are required and/or suggested.
26+
Depending on the package type and the referenced `Cake.Core`-version different target versions are required and/or suggested.
2727
Missing a required target version will raise [CCG0007](../rules/ccg0007) as an error
2828
while missing a suggested target version will raise [CCG0007](../rules/ccg0007) as a warning.
2929

30-
* Cake.Core < 1.0.0
30+
* Package type: addin
31+
* Cake.Core < 1.0.0
32+
* Required: `netstandard2.0`
33+
* Suggested: `net461`
34+
* alternative: `net46`
35+
* Cake.Core >= 1.0.0
36+
* Required: `netstandard2.0`
37+
* Suggested: `net461`
38+
* alternative: `net46`
39+
* Suggested: `net5.0`
40+
* Package type: module
3141
* Required: `netstandard2.0`
32-
* Suggested: `net461`
33-
* alternative: `net46`
34-
* Cake.Core >= 1.0.0
35-
* Required: `netstandard2.0`
36-
* Suggested: `net461`
37-
* alternative: `net46`
38-
* Suggested: `net5.0`
3942

4043
## Related rules
4144

src/Guidelines/build/TargetFrameworkVersions.targets

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
<Target
99
Name="_CheckTargetFrameworkVersions"
1010
AfterTargets="BeforeBuild"
11-
BeforeTargets="CoreBuild">
11+
BeforeTargets="CoreBuild"
12+
DependsOnTargets="EnsureProjectTypeIsSet">
13+
1214
<!-- All other rules have some "configuration" here, this rules required/suggested targets are hard-coded in the task. Sadly. -->
1315

1416
<TargetFrameworkVersions
1517
References="@(PackageReference)"
1618
TargetFramework="$(TargetFramework)"
1719
TargetFrameworks="$(TargetFrameworks)"
1820
Omitted="@(CakeContribGuidelinesOmitTargetFramework)"
19-
ProjectFile="$(MSBuildProjectFullPath)" />
21+
ProjectType="$(CakeContribGuidelinesProjectType)" />
2022
</Target>
2123
</Project>

src/Tasks.IntegrationTests/E2eTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,25 @@ public void Referencing_CakeCore_With_all_targets_raises_no_warning()
251251
result.WarningLines.Should().BeEmpty();
252252
}
253253

254+
[Fact]
255+
public void Referencing_CakeCore_With_NetStandard_raises_no_warning_If_PackageType_Is_Module()
256+
{
257+
// given
258+
fixture.WithPackageReference("Cake.Core", "1.0.0", "all");
259+
fixture.WithTargetFrameworks("netstandard2.0");
260+
fixture.WithCustomContent(@"
261+
<PropertyGroup>
262+
<PackageId>Cake.Buildsystems.Module</PackageId>
263+
</PropertyGroup>");
264+
265+
// when
266+
var result = fixture.Run();
267+
268+
// then
269+
result.IsErrorExitCode.Should().BeFalse();
270+
result.WarningLines.Should().BeEmpty();
271+
}
272+
254273
[Fact]
255274
public void ProjectType_Default_Is_Addin()
256275
{

src/Tasks.Tests/CalculateProjectTypeTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Linq;
2-
31
using CakeContrib.Guidelines.Tasks.Tests.Fixtures;
42

53
using FluentAssertions;

src/Tasks.Tests/Fixtures/CalculateProjectTypeFixture.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Linq;
43

54
using Microsoft.Build.Framework;
65

7-
using Moq;
8-
96
namespace CakeContrib.Guidelines.Tasks.Tests.Fixtures
107
{
118
public class CalculateProjectTypeFixture : BaseBuildFixture<CalculateProjectType>

src/Tasks.Tests/Fixtures/TargetFrameworkVersionsFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public void WithCakeCoreReference(int major = 0, int minor = 0, int patch = 0)
5656
references.Add(cakeRef.Object);
5757
}
5858

59-
public void WithProjectFile(string fileName)
59+
public void WithProjectType(string projectType)
6060
{
61-
Task.ProjectFile = fileName;
61+
Task.ProjectType = projectType;
6262
}
6363
}
6464
}

src/Tasks.Tests/TargetFrameworkVersionsTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,37 @@ public void Should_Not_Warn_If_All_References_for_Cake_Version_is_1_0_0_is_prese
137137
fixture.BuildEngine.ErrorEvents.Should().HaveCount(0);
138138
fixture.BuildEngine.WarningEvents.Should().HaveCount(0);
139139
}
140+
141+
[Fact]
142+
public void Should_Error_If_ProjectType_Is_Module_And_Reference_Is_Missing()
143+
{
144+
// given
145+
var fixture = new TargetFrameworkVersionsFixture();
146+
fixture.WithCakeCoreReference(1);
147+
fixture.WithProjectType("module");
148+
149+
// when
150+
fixture.Execute();
151+
152+
// then
153+
fixture.BuildEngine.ErrorEvents.Should().HaveCount(1);
154+
}
155+
156+
[Fact]
157+
public void Should_Not_Warn_If_ProjectType_Is_Module_And_Reference_Is_NetStandard()
158+
{
159+
// given
160+
var fixture = new TargetFrameworkVersionsFixture();
161+
fixture.WithCakeCoreReference(1);
162+
fixture.WithTargetFramework("netstandard2.0");
163+
fixture.WithProjectType("module");
164+
165+
// when
166+
fixture.Execute();
167+
168+
// then
169+
fixture.BuildEngine.ErrorEvents.Should().HaveCount(0);
170+
fixture.BuildEngine.WarningEvents.Should().HaveCount(0);
171+
}
140172
}
141173
}

src/Tasks/CcgLogError.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
using System.Diagnostics.CodeAnalysis;
2-
31
using CakeContrib.Guidelines.Tasks.Extensions;
42

53
using Microsoft.Build.Framework;
64
using Microsoft.Build.Utilities;
75

6+
// ReSharper disable UnusedMember.Global
87
namespace CakeContrib.Guidelines.Tasks
98
{
109
/// <summary>
1110
/// This is a convenience-Task to call CcgError from inside the msbuild.
1211
/// </summary>
13-
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "Needed in Tasks")]
14-
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Needed in Tasks")]
15-
[SuppressMessage("ReSharper", "UnusedType.Global", Justification = "Used as Task")]
1612
public class CcgLogError : Task
1713
{
1814
/// <summary>

src/Tasks/CcgLogWarning.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
using System.Diagnostics.CodeAnalysis;
2-
31
using CakeContrib.Guidelines.Tasks.Extensions;
42

53
using Microsoft.Build.Framework;
64
using Microsoft.Build.Utilities;
75

6+
// ReSharper disable UnusedMember.Global
87
namespace CakeContrib.Guidelines.Tasks
98
{
109
/// <summary>
1110
/// This is a convenience-Task to call CcgWarning from inside the msbuild.
1211
/// </summary>
13-
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global", Justification = "Needed in Tasks")]
14-
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global", Justification = "Needed in Tasks")]
15-
[SuppressMessage("ReSharper", "UnusedType.Global", Justification = "Used as Task")]
1612
public class CcgLogWarning : Task
1713
{
1814
/// <summary>

0 commit comments

Comments
 (0)