SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.25k stars 754 forks source link

SpecFlow.Tools.MsBuild.GenerateAll error with dotnet build in Specflow 2.4.1 and NUnit #1624

Closed fionnaos closed 4 years ago

fionnaos commented 5 years ago

SpecFlow Version:

Used Test Runner

Project Format of the SpecFlow project

.feature.cs files are generated using

Visual Studio Version

N/A - issue building from command line only

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

Are the latest Visual Studio updates installed?

N/A - issue building from command line only

.NET Framework:

Test Execution Method:

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

  <specFlow>
   <unitTestProvider name="NUnit" />
  </specFlow>

Repro Project

https://github.com/fionnaos/specflow241-nunit

Issue Description

Trying to change from using Custom Tool for feature.cs file generation to using SpecFlow.Tools.MsBuild.Generation. It works fine from within Visual Studio, but when run from the command line, as done in our Jenkins server, the 'dotnet build' command returns:

C:\Users\Fionna.OSullivan\source\repos\DummySolution\packages\SpecFlow.Tools.MsBuild.Generation.2.4.1\build\SpecFlow.Tools.MsBuild.Generation.targets(72,5): error MSB4062: The "TechT
alk.SpecFlow.Tools.MsBuild.GenerateAll" task could not be loaded from the assembly C:\Users\Fionna.OSullivan\source\repos\DummySolution\packages\SpecFlow.2.4.1\tools\specflow.exe. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Frame
work.ITask.[C:\Users\Fionna.OSullivan\source\repos\DummySolution\DummySolution\DummySolution.csproj]

Using MSBuild instead of dotnet gives an error about UpToDateCheckBuild in Specflow.Tools.MsBuild.Generation.props,

C:\Users\Fionna.OSullivan\source\repos\DummySolution\packages\SpecFlow.Tools.MsBuild.Generation.2.4.1\build\SpecFlow.Tools.MsBuild.Generation.props(60,80): error MSB4066: The attribu
te "Original" in element <UpToDateCheckBuild> is unrecognized. [C:\Users\Fionna.OSullivan\source\repos\DummySolution\DummySolution\DummySolution.csproj]

which seems to be about MSBuild not handling things from .NET Core. This also can be reproduced on a local machine, and with .NET Framework version 4.6.1, 4.7.1 and 4.7.2. Linked solution is as bare bones as possible to reproduce.

Steps to Reproduce

cd DummySolution\DummySolution
dotnet build
SabotageAndi commented 5 years ago

If you use dotnet build the process is running in .NET Core. SpecFlow 2.4 doesn't support .NET Core. You have to use SpecFlow 3 or build with msbuild from Visual Studio 2017. The msbuild error from you is I think, because you are using MSBuild from VS 2015.

fionnaos commented 5 years ago

If you use dotnet build the process is running in .NET Core. SpecFlow 2.4 doesn't support .NET Core.

Okay, I have been using dotnet build in the CI servers for almost a year with Specflow 2.4.1. Could this then be documented in https://specflow.org/documentation/Generate-Tests-from-MsBuild/ that this GenerateAll task specifically won't work with dotnet and Specflow versions less than 3?

You have to use SpecFlow 3 or build with msbuild from Visual Studio 2017. The msbuild error from you is I think, because you are using MSBuild from VS 2015.

Thanks, that helped! I was using MSBuild from the .NET Framework installation, not from Visual Studio build tools.

SabotageAndi commented 4 years ago

Closed because resolved

github-actions[bot] commented 3 years ago

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.