Specflow-GenerateFeatureFileCodeBehindTask意外失败

问题描述 投票:1回答:2

我对SpecFlow有问题。我们正在使用Azure Devops,当我在本地计算机上构建解决方案时,它可以正常运行,但是在Azure Devops构建期间,出现以下错误:

[error]C:\Windows\ServiceProfiles\NetworkService\.nuget\packages\specflow.tools.msbuild.generation\3.1.86\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): Error MSB4018: The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'. The system cannot find the file specified.
File name: 'TechTalk.SpecFlow, Version=3.1.0.0, Culture=neutral, PublicKeyToken=0778194805d6db41'
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
   at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
   at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)
   at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType)
   at TechTalk.SpecFlow.Generator.Plugins.GeneratorPluginLoader.LoadPlugin(PluginDescriptor pluginDescriptor)
   at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.LoadPlugins(ObjectContainer container, GeneratorPluginEvents generatorPluginEvents, UnitTestProviderConfiguration unitTestProviderConfiguration, IEnumerable`1 generatorPlugins)
   at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.CreateContainer(SpecFlowConfigurationHolder configurationHolder, ProjectSettings projectSettings, IEnumerable`1 generatorPluginInfos, IObjectContainer parentObjectContainer)
   at SpecFlow.Tools.MsBuild.Generation.WrappedGeneratorContainerBuilder.BuildGeneratorContainer(SpecFlowConfigurationHolder specFlowConfigurationHolder, ProjectSettings projectSettings, IReadOnlyCollection`1 generatorPluginInfos, IObjectContainer rootObjectContainer)
   at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTaskExecutor.Execute()
   at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
        <PackageReference Include="FluentAssertions" Version="5.10.2" />
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
        <PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
        <PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
        <PackageReference Include="NUnit" Version="3.12.0" />
        <PackageReference Include="Selenium.Support" Version="3.141.0" />
        <PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
        <PackageReference Include="SpecFlow" Version="3.1.86" />
        <PackageReference Include="SpecFlow.MsTest" Version="3.1.86" />
        <PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.1.86" />

我尝试将其与nUnitMsTestxUnit结合使用,但始终失败。目标框架:.NET Core 3.1。构建代理:vs2019-win2019

selenium azure-devops nunit specflow azure-automation
2个回答
0
投票

错误消息说:

无法加载文件或程序集'TechTalk.SpecFlow,版本= 3.1.0.0,区域性=中性,PublicKeyToken = 0778194805d6db41'。该系统找不到指定的文件。文件名:'TechTalk.SpecFlow,版本= 3.1.0.0

您已安装SpecFlow v3.1.86。我希望它会加载与NuGet软件包版本匹配的TechTalk.SpecFlow 3.1.86。

任何一个:

  • 使用程序包管理器控制台卸载并重新安装SpecFlow程序包:

    uninstall-package SpecFlow -force -project NameOfYourTestProject
    install-package SpecFlow -version 3.1.86 -project NameOfYourTestProject
    
  • 编辑测试项目的.csproj文件,并确保导入DLL文件的<Reference>元素指向正确的文件

    <Reference Include="TechTalk.SpecFlow, Version=3.0.0.0, Culture=neutral, PublicKeyToken=..., processorArchitecture=MSIL">
      <HintPath>..\packages\SpecFlow.3.1.86\lib\FRAMEWORK_VERSION\TechTalk.SpecFlow.dll</HintPath>
    </Reference>
    

    注意:取决于测试项目的.NET Framework版本,用net45,netstandard2.0等替换FRAMEWORK_VERSION

您可以始终打开Windows File Explorer并浏览到DLL文件,以发现正确的路径。

尽力而为,请尝试从命令行手动还原NuGet软件包,假设%PATH%中有NuGet.exe(有关更多信息,请参见https://docs.microsoft.com/en-us/nuget/install-nuget-client-tools

nuget restore Path/To/YourSolution.sln

0
投票

具有相同的问题,原来是.net核心SDK和Specflow之间的版本问题。我们将.net core sdk降级到3.1.102,这有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.