Specflow: MSTest.AssemblyHooks.cs violates SA1210 rule

Created on 28 Jan 2020  Â·  4Comments  Â·  Source: SpecFlowOSS/SpecFlow

SpecFlow Version:

  • [x] 3.1.80
  • [ ] 3.0
  • [ ] 2.4
  • [ ] 2.3
  • [ ] 2.2
  • [ ] 2.1
  • [ ] 2.0
  • [ ] 1.9

Used Test Runner

  • [ ] SpecFlow+Runner
  • [x] MSTest
  • [ ] NUnit
  • [ ] Xunit

Version number: 3.1.80

Project Format of the SpecFlow project

  • [ ] Classic project format using packages.config
  • [ ] Classic project format using <PackageReference> tags
  • [x] Sdk-style project format

.feature.cs files are generated using

  • [x] SpecFlow.Tools.MsBuild.Generation NuGet package
  • [ ] SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • [x] VS 2019
  • [ ] VS 2017
  • [ ] VS 2015

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • [ ] Enabled
  • [x] Disabled

Are the latest Visual Studio updates installed?

  • [x] Yes
  • [ ] No, I use Visual Studio version <Major>.<Minor>.<Patch>

.NET Framework:

  • [x] >= .NET 4.5
  • [ ] before .NET 4.5
  • [ ] .NET Core 2.0
  • [x] .NET Core 2.1
  • [ ] .NET Core 2.2
  • [ ] .NET Core 3.0

Test Execution Method:

  • [ ] Visual Studio Test Explorer
  • [ ] TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • [ ] Command line – PLEASE SPECIFY THE FULL COMMAND LINE

Issue Description

Follow-up issue to https://github.com/SpecFlowOSS/SpecFlow/issues/1848

Our projects have installed the "Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8". This includes the analyzer StyleCop.Analyzers with the default rule SA1210 "The using directives within a C# code file are not sorted alphabetically by namespace.".
For our release builds we have the flag TreatWarningsAsErrors = true, so we are not able to compile without errors anymore because of this specflow issue.

By fixing the issue https://github.com/SpecFlowOSS/SpecFlow/issues/1848 the wrong using order was introduced.

MSTest.AssemblyHooks.cs(1,1): error SA1210: Using directives should be ordered alphabetically by the namespaces.

MSTest.AssemblyHooks.cs:

using System.Diagnostics;
using System.CodeDom.Compiler;
using global::Microsoft.VisualStudio.TestTools.UnitTesting;
using global::TechTalk.SpecFlow;

[GeneratedCode("SpecFlow", "3.1.80")]
[TestClass]
public class ...
...

Steps to Reproduce

Create a test project (netcoreapp2.1 or net472)
Set true in csproj
add nuget packages: SpecFlow, SpecFlow.MsTest, SpecFlow.Tools.MsBuild.Generation version 3.1.80
add nuget package: Microsoft.CodeAnalysis.FxCopAnalyzers version 2.9.8
compile
you should see an error like this:
obj\Release\net472\MSTest.AssemblyHooks.cs(1,1): error SA1210: Using directives should be ordered alphabetically by the namespaces.[C:\MyProject\MyProject.csproj]

up-for-grabs

Most helpful comment

If you send us a PR with the correct order, we can release a fixed version probably tomorrow.

PR https://github.com/SpecFlowOSS/SpecFlow/pull/1865 created.

All 4 comments

If you send us a PR with the correct order, we can release a fixed version probably tomorrow.

PR https://github.com/SpecFlowOSS/SpecFlow/pull/1865 created.

Sorry for the delay. NuGet packages are uploading now to NuGet.org

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings