SpecFlow/MSBuild Codebehind Gen - 生成所有任务

SpecFlow/MSBuild Codebehind Gen - Generate All task

在我正在进行的项目中,我正在维护一些用 SpecFlow 编写的功能测试。我们的团队大约一年前开始使用 Visual Studio 2017,我们 最终 开始对我们的测试进行一些维护!

我们对我正在从事的项目的测试最初是用 SpecFlow 2.3.2 编写的,最后更新于 Visual Studio 2015 年。

已知 SpecFlowSingleFileGenerator 无法在 VS 2017 上运行,所以我昨天花了大部分时间更改我们的套件以使用 MSBuildSingleFileGenerator 而不是 this article in SpecFlow's official documentation[= 中详述的20=]

问题:
在本地,我可以构建我的解决方案,包括功能测试项目。 但是,当我尝试在我们的构建服务器上构建项目时,我不断收到以下错误:

[exec]  C:\CheckoutDirectory\My Awesome Project\packages\SpecFlow.Tools.MsBuild.Generation.2.3.2\build\SpecFlow.Tools.MsBuild.Generation.targets(45,5): 
error MSB4036: The "GenerateAll" task was not found. 
Check the following: 
  1.) The name of the task in the project file is the same as the name of the task class. 
  2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 
  3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin" directory. [C:\CheckoutDirectory\My Awesome Project\AwesomeProject.FeatureTest\AwesomeProject.FeatureTest.csproj]

我应该指出,我们的团队 没有 编写 MS Build 任务的经验,因为到目前为止我们还不需要;我们在 TeamCity 上使用 NAnt 构建脚本来管理我们的构建工作。很明显,错误消息 有用...如果我们知道 字面意思的话。

现在,通常正确答案是:Google。我 did that,此特定错误没有相关结果。

此外,这阻碍了我的团队,因为我们需要我们的构建工作。我没有时间进行必要的研究和教育以正确理解 MS Build 技术的工作原理。那得晚点来。

问题:
请记住,SpecFlow 破坏了我们的流程,并且我们的团队缺乏关于 MS Build 系统的知识:我需要知道如何解决 "GenerateAll" task was not found 错误。我该怎么做才能解决这个问题?

次要问题:
我也愿意横向思考。有什么方法可以破解 VS 2017 或 SpecFlow 来使 SpecFlowSingleFileGenerator "compatible" 彼此?这里的objective是NOT是为了避免改动,而是为了控制改动。我需要一条从旧文件生成器过渡到 MS 构建生成系统的路径。

附加信息: 所以,我做了一些挖掘,发现了 SpecFlow.Tools.MsBuild.Generation.targets 文件中调用 "GenerateAll" 的地方:

<Target Name="UpdateFeatureFilesInProject"  
        DependsOnTargets="BeforeUpdateFeatureFilesInProject"  
        Inputs="@(SpecFlowFeatureFiles)" Outputs="@(SpecFlowFeatureFiles->'%(RelativeDir)\%(Filename).feature.cs')">
  <GenerateAll
    ShowTrace="$(ShowTrace)"

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

    ProjectPath="$(MSBuildProjectFullPath)"
    ForceGeneration="$(ForceGeneration)"
    VerboseOutput="$(VerboseOutput)"
    DebugTask="$(SpecFlow_DebugMSBuildTask)" 
    >
    <Output TaskParameter="GeneratedFiles" ItemName="SpecFlowGeneratedFiles" />
  </GenerateAll>
</Target>

因为我已经确认正在将其复制到构建服务器,所以情况更加神秘。看起来 NuGet 包被忠实地拉下了。因此,我无法弄清楚为什么我的本地副本的行为与构建服务器上的副本不同。

我不确定你在哪里找到这个声明:

The SpecFlowSingleFileGenerator is known to not work on VS 2017

SpecFlowSingleFileGenerator 在 VS2015、VS2017 和 VS2019 中运行。我们将其视为一项遗留功能,但它仍然存在。几周以来默认情况下它是禁用的,但您可以在选项中启用它。

适用于 SpecFlow >= 2.3.2 和 2.4。对于 SpecFlow 3,您必须使用 MSBuild 集成。旧版本的 SpecFlow 存在一些问题,但它也可以工作。这取决于您的设置。


关于您的 MSBuild 错误:

SpecFlow < 3.0 的 MSBuild 任务在 specflow.exe 中。它在您的构建服务器上吗? 它是 SpecFlow NuGet 包的一部分。如果 MSBuild 找不到任务所在的程序集,通常会出现此类错误。

对于 MSBuild 的 "debugging" 问题,我强烈建议使用 MSBuild 结构化日志查看器 (http://msbuildlog.com/)。有了它,就可以轻松查看构建中发生的情况。

我们在此处提供了使用 SpecFlow 2.3.2 生成 MSBuild 代码隐藏的示例:https://github.com/techtalk/SpecFlow-Examples/tree/master/MSBuild/OldCSProj_SpecFlow232

您可以将您的项目与此示例进行比较。


完全披露:我是 SpecFlow 的维护者之一。