Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature File Codebehind MSBuild Task Doesn't Handle Blank RootNamespace #1605

Closed
10 of 32 tasks
idg10 opened this issue Jun 6, 2019 · 1 comment · Fixed by #1606
Closed
10 of 32 tasks

Feature File Codebehind MSBuild Task Doesn't Handle Blank RootNamespace #1605

idg10 opened this issue Jun 6, 2019 · 1 comment · Fixed by #1606

Comments

@idg10
Copy link
Contributor

idg10 commented Jun 6, 2019

SpecFlow Version:

  • 3.0
  • 2.4
  • 2.3
  • 2.2
  • 2.1
  • 2.0
  • 1.9

Used Test Runner

  • SpecFlow+Runner
  • MSTest
  • NUnit
  • Xunit

Version number: 3.0.213

Project Format of the SpecFlow project

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

.feature.cs files are generated using

  • SpecFlow.Tools.MsBuild.Generation NuGet package
  • SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • VS 2019
  • VS 2017
  • VS 2015

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • Enabled
  • Disabled

Are the latest Visual Studio updates installed?

  • Yes
  • No

.NET Framework:

  • >= .NET 4.5
  • before .NET 4.5
  • .NET Core 2.0
  • .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

<SpecFlow> Section in app.config or content of specflow.json

No config file in use.

Issue Description

If you set the <RootNamespace> element of an SDK-style project to be empty, SpecFlow complains. In V2, it used to fall back to a default namespace, and the code to do that is still in there, but the Feature File Codebehind MSBuild Task marks the property by which it discovers the default namespace as [Required] meaning that if you're using this new codebehind generation approach, you can no longer have an empty root namespace

Steps to Reproduce

  1. Create a simple test project that uses SpecFlow. (Any test runner.)
  2. Edit the .csproj so that it has <RootNamespace></RootNamespace> in it (or set the default namespace to be empty in the project settings UI.
  3. Add a SpecFlow feature file.
  4. Build

You will get an error complaining that the root namespace is required.

This happens because MSBuild does not distinguish between empty strings and null. Setting the root namespace to an empty string effectively tells it that there is no value for that setting, causing the execution of the SpecFlow feature codebehind generator task to fail.

More information

Some companies like to have a file folder structure that directly reflects the namespace hierarchy. In cases where you need to put things in external namespaces (as is a common convention for certain extension methods) there is no common root namespace, so you need the folder structure to reflect the entire namespace, at which point you need to set <RootNamespace> to be empty, otherwise VS will put the wrong namespaces on new files that you add.

@lock
Copy link

lock bot commented Jul 8, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant