sashoalm
sashoalm

Reputation: 79467

SpecFlow .feature.cs file gets duplicated when feature file is edited

When I edit Foo.feature, SpecFlow creates a new Foo1.feature.cs instead of overwriting Foo.feature.cs. The duplicated file then causes compile errors due to duplicated symbols.

It happens only for one of the .feature files in my project - all others behave normally. All the .feature and .feature.cs files are under source control and added to the Foo.csproj file.

Upvotes: 2

Views: 2949

Answers (1)

sashoalm
sashoalm

Reputation: 79467

I think I found the problem - in my .csproj file I had this entry:

<None Include="Foo.feature">
  <Generator>SpecFlowSingleFileGenerator</Generator>
  <LastGenOutput>Foo1.feature.cs</LastGenOutput>
</None>

I think the <LastGenOutput> was confusing SpecFlow. I don't know where it came from, but changing it to <LastGenOutput>Foo.feature.cs</LastGenOutput> fixed the issue.

Edit: I just found out that a missing <LastGenOutput> tag can also cause a duplicate Foo1.feature.cs file to be created. So if the tag is missing create it and put the correct filename in it.

After googling for SpecFlow and "LastGenOutput", I found this thread - https://groups.google.com/forum/#!topic/specflow/SpOihmvoAOQ. It outlines the same problem and solution:

Issue may be very annoying. Possible solution (do at you own risk!)

  1. delete all YourFeature1.feature.cs files in Visual Studio. Save project.
  2. close Visual Studio, open your .csproj file with notepad
  3. find the lines similar to this one:

YourFeature1.feature.cs

change them to

YourFeature.feature.cs

save, load project in Visual Studio. Enjoy.

But you have to already know the solution in order to find that thread.

Upvotes: 4

Related Questions