33

I've got ~30 SpecFlow feature files, and I recently removed the Foo.feature.cs files from source control because I got sick of resolving merge conflicts in Designer Generated code.

I did not exclude or remove these files from my Visual Studio project, so Visual Studio still thinks they should be there, they are just missing on the hard disk.

Ideally I'd like to just click on a root folder and regenerate all the code behind files, but no such option exists for VS 2010 and SpecFlow 1.9. I'd even be OK with programmatically regenerating them from the command line, creating another custom tool or adding a pre-compile build event.

Is there a way to regenerate all of the the Designer generated code behind files for SpecFlow features (*.feature.cs files) without right-clicking on each .feature file and clicking "Run Custom Tool"?

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • 1
    Well you can also just perform a save on the .Feature file as that automatically performs the "Run Custom Tool". Otherwise its going to be a case of simulating the call to RunCustomTool – AlSki Sep 22 '14 at 15:50
  • I was hoping it didn't involve any sort of operation on each file individually. – Greg Burghardt Sep 22 '14 at 16:59
  • 1
    you can't right click on the project and choose 'Regenerate feature files'? Is that option not available in vs2010? – Sam Holder Sep 22 '14 at 19:31
  • 1
    @SamHolder Oh, good lord. It's right there in front of my face. If you post that as an answer, I'll mark it. Thanks! – Greg Burghardt Sep 22 '14 at 20:49
  • No problem. Answered now. Didn't want to before in case I got the 'not in my version of visual studio' down votes :) – Sam Holder Sep 22 '14 at 20:55

2 Answers2

68

You can right click on the project and choose 'regenerate feature files' to do them all at once.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • Thanks for this answer. I was about to do something I would have later regretted had I not come upon this answer :) – BradStell May 20 '16 at 19:36
  • Weird, I wonder why that menu option isn't available when you right-click on individual feature files. – Grant Birchmeier Jun 14 '17 at 21:47
  • 1
    @GrantBirchmeier: You can choose "Run custom tool" from the context menu of an individual feature file. Not very intuitive, but that's how you do it. – Greg Burghardt Aug 04 '17 at 00:27
10

It runs much quicker from the command prompt. Go to your Specflow package tools folder and run the following command line. It also ensures the correct Specflow version is added to the files.

specflow.exe generateall <My_Testing.csproj>
Stuart Dobson
  • 3,001
  • 4
  • 35
  • 37
  • Very nice! Great command line solution, especially useful for CI builds if you need to regenerate the tests on the fly, and not have to check the .feature.cs files into source control. – Greg Burghardt Apr 09 '18 at 11:57
  • This is especially handy if you do not use Nuget, because Specflow looks for your packages folder, and if it can't find it, will generate feature files with 1.9 even though you're using 2.3+ (see here https://groups.google.com/forum/#!topic/SpecFlow/f0rtrenUeOQ) – Stuart Dobson Apr 09 '18 at 21:39