首页 > 解决方案 > 代码后面的规范流有语法错误或重复代码

问题描述

我有一个由几个项目组成的解决方案。我的解决方案中有 3 类项目。第一类仅包括 .feature 文件。第二类只包括绑定。第三个包括驱动程序,其中包括绑定中使用的一组函数,以与我正在测试的软件接口进行通信。

当我构建我的解决方案时,文件背后的一些代码 (.feature.cs) 已损坏。以下是我构建解决方案后得到的屏幕截图:

Visual Studio 中的构建错误

Visual Studio 中的构建错误

以下是损坏的 .feature.cs 文件的示例:

    // ------------------------------------------------------------------------------
//  <auto-generated>
//      This code was generated by SpecFlow (http://www.specflow.org/).
//      SpecFlow Version:2.3.0.0
//      SpecFlow Generator Version:2.3.0.0
// 
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </auto-generated>
// ------------------------------------------------------------------------------
#region Designer generated code
#pragma warning disable
namespace AcceptanceTests.Controllers.Images
{
    using TechTalk.SpecFlow;


    [System.CodeDom.Compiler.GeneratedCodeAttribute("TechTalk.SpecFlow", "2.3.0.0")]
    [System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute()]
    public partial class GetImagesFeature
    {

        private static TechTalk.SpecFlow.ITestRunner testRunner;

        pr// ------------------------------------------------------------------------------
//  <auto-generated>
//      This code was generated by SpecFlow (http://www.specflow.org/).
//      SpecFlow Version:2.3.0.0
//      SpecFlow Generator Version:2.3.0.0
// 
//      Changes to this file may cause incorrect behavior and will be lost if
//      the code is regenerated.
//  </auto-generated>
// ------------------------------------------------------------------------------
+ Designer generated code

注意这里有重复的代码块。似乎重新生成的代码被添加到旧代码中间的某个地方(我们看到“pr// ---”)。

另一个例子是包含语法错误的代码文件,例如缺少括号或格式不正确。

我的解决方案中的所有测试项目都有以下包:

单元测试提供程序是 mstest.v2。

到目前为止,我已尝试清理 %TEMP% 中的 SpecFlow 文件。我确保所有项目都安装了相同版本的 SpecFlow。我已经清理了解决方案并完成了重建。如果我在每个功能文件上单独运行自定义工具,我永远不会遇到这个问题。

我感谢您的帮助!

标签: c#msbuildspecflow

解决方案


该问题是由具有长名称、嵌套文件夹和长测试场景描述的项目引起的。我缩短了其中一个功能文件中的场景描述,该文件经常损坏其背后的代码,之后问题就消失了。


推荐阅读