Skip to content

Commit

Permalink
Merge pull request #675 from nunit/feat/drop-netstandard-16
Browse files Browse the repository at this point in the history
feat: Drop support of VS before 2019 version 16.3
  • Loading branch information
mikkelbu authored Jan 20, 2024
2 parents 72ae470 + a9c6db4 commit 01364d4
Show file tree
Hide file tree
Showing 18 changed files with 10 additions and 104 deletions.
7 changes: 2 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ Note that by contributing to NUnit.Analyzers, you assert that:

## Building the Project

First, make sure you have the right tools and templates on your machine. You'll need **Visual Studio 2017** or **Visual Studio 2019** and the **.NET Compiler Platform SDK**. The **.NET Compiler Platform SDK** can be installed via the **Visual Studio Installer**. Either
* check the **Visual Studio extension development** workload; open the **Visual Studio extension development** node in the summary tree to the right; and check the box for **.NET Compiler Platform SDK** (last under the optional components), or
* select the **Individual components** tab and check the box for **.NET Compiler Platform SDK** (at the top under the Compilers, build tools, and runtimes section).
First, make sure you have the right tools and templates on your machine. You'll need **Visual Studio 2019 version 16.3** (or newer) and the **.NET Compiler Platform SDK**. The **.NET Compiler Platform SDK** can be installed via the **Visual Studio Installer** under the **Individual components** tab and check the box for **.NET Compiler Platform SDK** (at the top of the **Compilers, build tools, and runtimes** section).

The project can now be built from within **Visual Studio 2017** or **Visual Studio 2019**, or by using the **Cake** script in the root folder.
The project can now be built from within **Visual Studio**, or by using the **Cake** script in the root folder.

### Building using Visual Studio

Expand All @@ -53,4 +51,3 @@ From Visual Studio one can debug the analyzers by adding a small test that illus
### Building using Cake

The command `.\build.ps1` will restore the packages necessary to build the solution, build the projects, and then run the tests. The script can also build the projects in **Release** mode using the option `--configuration=Release` or create NuGet Packages using the option `--target=Pack`. This will create a NuGet package under `package\Debug\` (for a `Debug` build) and the file will be named `NUnit.Analyzers.***.nupkg` where `***` depends upon the build type (`Debug` vs. `Release`) and the version. The NuGet package can then be referenced from another project.
You need to use the `--targetFramework=netstandard1.6` option to build a analyzer version for `netstandard1.6` (VS 2017), this version will not include the new DiagnosticSuppressor rules (NUnit3001-) as these require `netstandard2.0`.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This is a suite of analyzers that target the NUnit testing framework. Right now,

## Download ##

The latest stable release of the NUnit Analyzers is [available on NuGet](https://www.nuget.org/packages/NUnit.Analyzers/) or can be [downloaded from GitHub](https://github.com/nunit/nunit.analyzers/releases). Note that for Visual Studio 2017 one must use versions below 3.0. Version 3.0 and upwards require Visual Studio 2019, these versions also enables supression of compiler errors such as errors arising from nullable reference types.
The latest stable release of the NUnit Analyzers is [available on NuGet](https://www.nuget.org/packages/NUnit.Analyzers/) or can be [downloaded from GitHub](https://github.com/nunit/nunit.analyzers/releases). Note that for Visual Studio 2017 one must use versions below 3.0 - note that these versions are no longer updated, so version 2.10.0 is the last version that works in Visual Studio 2017. Version 3.0 and upwards require Visual Studio 2019 (version 16.3) or newer, these versions also enables supression of compiler errors such as errors arising from nullable reference types.

Prerelease nuget packages can be found on [MyGet](https://www.myget.org/feed/nunit-analyzers/package/nuget/NUnit.Analyzers). Please try out the package and report bugs and feature requests.

Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ before_build:
- cmd: dotnet --version

build_script:
- ps: .\build.ps1 --target="Appveyor" --configuration="Release" --targetFramework="netstandard1.6"
- ps: .\build.ps1 --target="Appveyor" --configuration="Release" --targetFramework="netstandard2.0"

# disable built-in tests.
test: off

artifacts:
- path: 'package\Release\netstandard1.6\NUnit.Analyzers*.nupkg'
- path: 'package\Release\netstandard2.0\NUnit.Analyzers*.nupkg'

deploy:
Expand Down
12 changes: 1 addition & 11 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ var targetFramework = Argument("targetFramework", "netstandard2.0");
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////

var isNetstandard16Build = targetFramework == "netstandard1.6";
var isNetstandard20Build = targetFramework == "netstandard2.0";

var version = isNetstandard20Build
? "4.0.0"
: "2.11.0";
var version = "4.0.0";

var isAppveyor = BuildSystem.IsRunningOnAppVeyor;
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
Expand Down Expand Up @@ -59,11 +54,6 @@ Setup(context =>
if (tag.IsTag)
{
var tagName = tag.Name;
if (isNetstandard16Build && tagName.StartsWith("3"))
{
tagName = '2' + tagName.Substring(1);
}

packageVersion = tagName;
packageVersionString = tagName;
}
Expand Down
2 changes: 1 addition & 1 deletion documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Rules which improve assertions in the test code.
## Suppressor Rules (NUnit3001 - )

Rules which suppress compiler errors based on context. Note that these rules are only available in the .NET Standard 2.0
builds (version 3.0.0 and above) which require Visual Studio 2019.
builds (version 3.0.0 and above) which require Visual Studio 2019 (version 16.3) or newer.

| Id | Title | :mag: | :memo: | :bulb: |
| :-- | :-- | :--: | :--: | :--: |
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>NUnit Framework Analyzers</Description>
<Company>NUnit Project</Company>
<Product>NUnit Analyzers</Product>
<Copyright>Copyright © 2018-2023 NUnit project</Copyright>
<Copyright>Copyright © 2018-2024 NUnit project</Copyright>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public abstract class BaseConditionConstraintAnalyzer : BaseAssertionAnalyzer

protected static bool IsRefStruct(IOperation operation)
{
#if NETSTANDARD2_0_OR_GREATER
return operation.Type?.TypeKind == TypeKind.Struct && operation.Type.IsRefLikeType;
#else
return false;
#endif
}

protected static bool IsBinaryOperationNotUsingRefStructOperands(IOperation actual, BinaryOperatorKind binaryOperator)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if !NETSTANDARD1_6

using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -52,5 +50,3 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if !NETSTANDARD1_6

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
Expand Down Expand Up @@ -464,5 +462,3 @@ private static SuppressionDescriptor CreateSuppressionDescriptor(string suppress
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if !NETSTANDARD1_6

using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand Down Expand Up @@ -279,5 +277,3 @@ memberAccessExpression.Expression is InvocationExpressionSyntax awaitedInvocatio
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if !NETSTANDARD1_6

using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -60,5 +58,3 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
}
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ namespace NUnit.Analyzers.DisposeFieldsInTearDown
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class DisposeFieldsAndPropertiesInTearDownAnalyzer : DiagnosticAnalyzer
{
#if NETSTANDARD2_0_OR_GREATER
private static readonly char[] AdditionalDisposalMethodsSeparators = { ',', ';', ' ' };
#endif

// Methods that are considered to be Dispoing an instance.
private static readonly ImmutableHashSet<string> StandardDisposeMethods = ImmutableHashSet.Create(
Expand Down Expand Up @@ -143,15 +141,13 @@ private static void AnalyzeDisposableFields(SyntaxNodeAnalysisContext context)

ImmutableHashSet<string> disposeMethods = StandardDisposeMethods;

#if NETSTANDARD2_0_OR_GREATER
// Are there any additional methods configured that are considered Dispose Methods
// e.g. DisposeIfDisposeable or Release
AnalyzerConfigOptions options = context.Options.AnalyzerConfigOptionsProvider.GetOptions(classDeclaration.SyntaxTree);
if (options.TryGetValue("dotnet_diagnostic.NUnit1032.additional_dispose_methods", out string? value))
{
disposeMethods = disposeMethods.Union(value.Split(AdditionalDisposalMethodsSeparators, StringSplitOptions.RemoveEmptyEntries));
}
#endif

HashSet<string> symbolNames = new(symbols.Keys);

Expand Down Expand Up @@ -542,14 +538,12 @@ private static void DisposedIn(Parameters parameters, HashSet<string> disposals,

private static string? GetIdentifier(ExpressionSyntax expression)
{
#if NETSTANDARD2_0_OR_GREATER
// Account for 'Release(field!)'
if (expression is PostfixUnaryExpressionSyntax postfixUnaryExpression &&
postfixUnaryExpression.IsKind(SyntaxKind.SuppressNullableWarningExpression))
{
expression = postfixUnaryExpression.Operand;
}
#endif

if (expression is IdentifierNameSyntax identifierName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,12 @@ internal static bool CanAssignTo(this TypedConstant @this, ITypeSymbol target, C
if (argumentValue is null)
{
if (
#if NETSTANDARD1_6
target.IsReferenceType
#else
(target.IsReferenceType && (target.NullableAnnotation != NullableAnnotation.NotAnnotated || suppressNullableWarning))
#endif
|| target.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
{
return true;
}

#if !NETSTANDARD1_6
if (typeParameter is not null)
{
if (typeParameter.HasValueTypeConstraint ||
Expand All @@ -101,7 +96,6 @@ internal static bool CanAssignTo(this TypedConstant @this, ITypeSymbol target, C
// Either no constraint or class?
return true;
}
#endif
}
else
{
Expand Down
4 changes: 0 additions & 4 deletions src/nunit.analyzers/Extensions/ExpressionSyntaxExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ internal static class ExpressionSyntaxExtensions

public static bool IsSuppressNullableWarning(this ExpressionSyntax expression)
{
#if NETSTANDARD1_6
return false;
#else
return expression.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.SuppressNullableWarningExpression);
#endif
}
}
}
4 changes: 0 additions & 4 deletions src/nunit.analyzers/Helpers/DiagnosticExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if !NETSTANDARD1_6

using System;
using System.Reflection;
using Microsoft.CodeAnalysis;
Expand All @@ -16,5 +14,3 @@ public static object[] Arguments(this Diagnostic diagnostic)
}
}
}

#endif
32 changes: 0 additions & 32 deletions src/nunit.analyzers/SymbolEqualityComparer.cs

This file was deleted.

11 changes: 2 additions & 9 deletions src/nunit.analyzers/nunit.analyzers.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>NUnit.Analyzers</RootNamespace>
<TargetFrameworks>netstandard2.0;netstandard1.6</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>

<!-- https://docs.microsoft.com/en-us/nuget/reference/nuspec#developmentdependency -->
<developmentDependency>true</developmentDependency>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.11.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.6'">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.10.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.11.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/nunit.analyzers/nunit.analyzers.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<description>
This package includes analyzers and code fixes for test projects using NUnit 3. The analyzers will mark wrong usages when writing tests, and the code fixes can be used to used to correct these usages.

Version 3.0 and upwards works in Visual Studio 2019 and also enables supression of compiler errors such as errors arising from nullable reference types. For Visual Studio 2017 one must use versions below 3.0.
Version 3.0 and upwards works in Visual Studio 2019 (version 16.3) or newer and also enables supression of compiler errors such as errors arising from nullable reference types. For Visual Studio 2017 one must use versions below 3.0 - note that these versions are no longer updated, so version 2.10.0 is the last version that works in Visual Studio 2017.
</description>
<releaseNotes>See the release notes on https://github.com/nunit/nunit.analyzers/blob/master/CHANGES.txt.</releaseNotes>
<copyright>Copyright (c) 2018-2023 NUnit project</copyright>
<copyright>Copyright (c) 2018-2024 NUnit project</copyright>
<tags>nunit, analyzers, roslyn-analyzers</tags>
</metadata>
<!-- The convention for analyzers is to put language agnostic dlls in analyzers\portable50 and language specific analyzers in either analyzers\portable50\cs or analyzers\portable50\vb -->
Expand Down

0 comments on commit 01364d4

Please sign in to comment.