2
votes

I am attempting to generate a Visual Studio solution that uses SpecFlow feature files. I would like to be able to generate the feature.cs source files externally via the specflow.exe /generateall command. My problem is that when I use the specflow command line tool the namespace in the generated file is very long and resembles the full path of the feature file.

Here is what the feature.cs file looks like after running specflow.exe /generateall :

// ------------------------------------------------------------------------------
//  <auto-generated>
//      This code was generated by SpecFlow (http://www.specflow.org/).
//      SpecFlow Version:1.7.1.0
//      SpecFlow Generator Version:1.7.0.0
//      Runtime Version:2.0.50727.5477
// 
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
namespace mylib.D.projectName.branch.project.folder.Private.scripts.Dev.Source.mylib.Features
{

The solution generation process uses source files from a source depot directory (perforce synced) and generates the solution and project files into a separate output folder (build directory).

This namespace is unusable as it contains path information specific to my workstation. I am trying to setup an automated testing tool that will use nunit-console to test the generated DLL. Since the namespace is specific I am not able to create a generic command to run the tests.

What I want to run:

nunit-console.exe /run:mylib.Features

What this namespace results in:

nunit-console.exe /run:mylib.D.projectName.branch.prjoect.folder.Private.scripts.Dev.Source.mylib.Features

Another piece of information is that if I simply edit the feature file from the generated solution in Visual Studio the feature.cs file is created with the correct namespace. It's only when I generate the feature.cs file from the command line tool that I get this long and unusable namespace value. I want to be able to edit feature files from a text editor and have the feature.cs files be generated as a pre-build step. The idea is for non Visual Studio users to be able to write specflow unit tests.

Thanks.

1
it looks like you are using an old version of SpecFlow, have you tried with 1.9?Sam Holder
No Sam I'll try that and see if it helps. ThanksScott Wilshire
No luck. For some reason the code generator wants to use an absolute path for the namespace. What code gen tool does that? Totally unusable!Scott Wilshire
So it generates full paths even with the 1.9 version?Sam Holder
Fixed: Use the CustomToolNamespace property in the feature file to set a custom tool namespace.Scott Wilshire

1 Answers

1
votes

When generating the VS solution set the CustomToolNamespace property for the ItemGroup that defines your feature file.