Build/Test Issues

Build fails with VS 2015 RTM

Started by ncrunchuser1 on 17,007 views

Project builds fail with the following message "..\packages\SpecFlow.1.9.0\tools\TechTalk.SpecFlow.targets (47, 5): Unable to cast object of type 'System.Xml.XmlComment' to type 'System.Xml.XmlElement'.".

The same project worked fine with VS 2015 RC but broke after upgrading to VS 2015 RTM. The tests are created with SpecFlow. The project builds fine in VS with no warnings and the SpecFlow runner and VS are both able to run the tests. Tried with version 1.9.0 and 1.8.1 with the same issue.
Hi,

Thanks for sharing this issue.

The problem appears to be a compatibility issue between SpecFlow and VS2015.

When NCrunch loads your project, it detects the reference to the SpecFlow binary and automatically includes the SpecFlow.targets file inside your project as an import. The reason for this is to allow NCrunch to be able to regenerate SpecFlow tests every time it builds your project, which is something that won't happen without this targets file included.

So it's the SpecFlow test/step generation that is causing the build to fail. I'm not sure how heavily you're using SpecFlow, but I expect that this issue may be a major one for you regardless of whether or not you use NCrunch. I recommend reporting it to them.

If you'd like to make your NCrunch build work in the same way as the Visual Studio build (and by-pass the error), open up the TechTalk.SpecFlow.targets file inside your Nuget packages directory, find the 'GenerateAll' task invocation on line 47, and comment it out. For example:

<Target Name="UpdateFeatureFilesInProject" DependsOnTargets="BeforeUpdateFeatureFilesInProject">
<!-- GenerateAll
ShowTrace="$(ShowTrace)"

BuildServerMode="$(BuildServerMode)"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"

ProjectPath="$(MSBuildProjectFullPath)"
ForceGeneration="$(ForceGeneration)"
VerboseOutput="$(VerboseOutput)">
<Output TaskParameter="GeneratedFiles" ItemName="SpecFlowGeneratedFiles" />
</GenerateAll -->
</Target>
Probably obvious, but you can also just change the target to have a condition by changing its first line like this and leaving the rest the same
<Target Name="UpdateFeatureFilesInProject" DependsOnTargets="BeforeUpdateFeatureFilesInProject" Condition="'$(NCrunch)' != '1'">
Thanks Graham!

I didn't know about that NCrunch parameter (guess I need to take a look at the NCrunch .targets file). That will come in handy in the future for sure!
I see there's no .targets file but I found the info about it and other environment variables in the online help. Guess I should read the manual more often :)

Thanks again!
Update on this:.

I did change to use the $(NCrunch) variable as Graham suggested. A couple of behaviors to be aware of if you use this:


  • You need to save the .feature file in order for NCrunch to pick up the latest changes
  • If you add the generated test file as a link, NCrunch will not detect changes in the .feature file - even after saving and the generated file is updated. The workaround is to modify a different file under test or right-click the test in NCrunch and choose "Reload and rebuild selected component"


Other than that, everything else seems to be working fine.
Changing the targets file is all well and good if you checkin/commit the targets file. This is not a solution if you are using nuget to download the package at compile time and therefore getting a new file on each compile. Also we don't commit these files to the repository so changing it would be a bit counter productive. Is there any other way around this to get Ncrunch working?
Hi Ruskin,

Another option could be to try adding the Condition="'$(NCrunch)' != '1'" to the <Import> tag in the project that is referencing the SpecFlow targets file. This will prevent the project from referencing the specflow build targets entirely.

Have you tried contacting SpecFlow about this problem? It's a bit of a concern if you're still encountering this issue so long after VS2015 hit RTM. I would think that a more solid solution would be available for this from their side by now.
Hi Remco,
Hmm the project file which uses the Specflow targets does not explicitly import the targets file.

I don't believe the problem is within VS2015 as the issue is only exposed while building via NCrunch.

There are few items which VS2015 simply builds out of box but when built via NCrunch, it fails, this being one of them. Most of the issues can be resolved by changing the NCrunch configuration settings, e.g. using "copy files to workspace" setting. Although it would be nice to get NCrunch build working a bit better with Nuget given than everything now is released using Nuget.

Any other suggestions?

Regards,
Ruskin
Hi Ruskin,

Sorry, I've just rechecked how this is put together. NCrunch is deliberately adding the targets reference behind the scenes so that it can re-generate the SpecFlow features automatically on each build. It's the SpecFlow feature re-generation step that's causing the build to fail, as this particular build task doesn't work inside the MSBuild 14.0 environment. I assume you are re-generating your SpecFlow features manually using the IDE integration.

I've noticed that SpecFlow have resolved this problem in their latest pre-release version. The actual release version of SpecFlow in Nuget hasn't been updated since 2012, so it's easy to understand why it isn't working properly.

I recommend trying the pre-release version of SpecFlow to see if this will work for you. Disabling or removing NCrunch's integration with SpecFlow's feature re-generation is actually very painful as this breaks the continuous flow you get when editing tests.
Thank you for that. A bit painful using pre-release packages but should suffice for now :).
Ruskin wrote:Thank you for that. A bit painful using pre-release packages but should suffice for now :).


Hopefully they release it soon :)

Post a reply

Log in to reply.