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.24k stars 754 forks source link

Could not resolve 'Microsoft.Extensions.Configuration.Abstractions' #2516

Closed czf closed 2 years ago

czf commented 2 years ago

SpecFlow Version

3.9.8

Which test runner are you using?

SpecFlow+ Runner

Test Runner Version Number

3.9.7

.NET Implementation

.NET 5.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Command line – PLEASE SPECIFY THE FULL COMMAND LINE

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

No response

Issue Description

dotnet test .csproj --no-build --verbosity=normal

Running tests in a TeamCity linux agent an exception is thrown because the Microsoft.Extensions.Configuration.Abstractions assembly can't be found. When I run the cli dotnet test on my windows machine the assembly is found.

I noticed in the reports log on my windows machine the runtime directory(C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App) is explored

Trying to resolve 'Microsoft.Extensions.Configuration.Abstractions' to 'C:\Users\xxx\.nuget\packages\Microsoft.Extensions.Configuration.Abstractions\3.0.0\lib\netcoreapp5.0
Could not resolve 'Microsoft.Extensions.Configuration.Abstractions' in folder 'C:\Users\xxx\.nuget\packages\Microsoft.Extensions.Configuration.Abstractions\3.0.0\lib\netcoreapp5.0'
Trying to resolve 'Microsoft.Extensions.Configuration.Abstractions' in folder 'C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.11'
Trying to resolve 'Microsoft.Extensions.Configuration.Abstractions' to 'C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.11\Microsoft.Extensions.Configuration.Abstra
Found file 'C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.11\Microsoft.Extensions.Configuration.Abstractions.dll' for assembly 'Microsoft.Extensions.Configuration
Resolved 'Microsoft.Extensions.Configuration.Abstractions' to C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\5.0.11\Microsoft.Extensions.Configuration.Abstractions.dll

On the Team City Linux agent the runtime directory is not explored.(/usr/share/dotnet/shared/Microsoft.AspNetCore.App)

Trying to resolve 'Microsoft.Extensions.Configuration.Abstractions' in folder '/usr/share/dotnet/sdk/NuGetFallbackFolder/Microsoft.Extensions.Configuration.Abstractions/3.0.0/lib/netcoreapp5.0'
Trying to resolve 'Microsoft.Extensions.Configuration.Abstractions' to '/usr/share/dotnet/sdk/NuGetFallbackFolder/Microsoft.Extensions.Configuration.Abstractions/3.0.0/lib/netcoreapp5.0/Microsoft.Extensions.Configuration.Abstractions.dll'
Trying to resolve 'Microsoft.Extensions.Configuration.Abstractions' to '/usr/share/dotnet/sdk/NuGetFallbackFolder/Microsoft.Extensions.Configuration.Abstractions/3.0.0/lib/netcoreapp5.0/Microsoft.Extensions.Configuration.Abstractions.exe'
Could not resolve 'Microsoft.Extensions.Configuration.Abstractions' in folder '/usr/share/dotnet/sdk/NuGetFallbackFolder/Microsoft.Extensions.Configuration.Abstractions/3.0.0/lib/netcoreapp5.0'

error: The type initializer for 'XXX' threw an exception. (3.5s)

Both environments have the same Microsoft.AspNetCore.App 5.0.11 runtime installed

Steps to Reproduce

I can't reproduce outside a TeamCity agent. The same project works on my windows development machine. A teammate using a mac also has this exception when running the tests

Link to Repro Project

No response

ayrtonDPI commented 2 years ago

I have the same issue with bitbucket pipelines, any solution to this yet?

czf commented 2 years ago

I have the same issue with bitbucket pipelines, any solution to this yet?

I ended up using an Assembly Resolver as a workaround.

private const string LINUX_EXTENSIONS_PATH = "/usr/share/dotnet/shared/Microsoft.AspNetCore.App/";
private const string MACOS_EXTENSIONS_PATH = "/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/";
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{

    string extensionsPath = RuntimeInformation.OSDescription.Contains("Linux") ? LINUX_EXTENSIONS_PATH : MACOS_EXTENSIONS_PATH;

    string filePath = extensionsPath + _runtimeVersionDirectory + "/" + args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";

    if (File.Exists(filePath))
    {
        var assembly = Assembly.LoadFile(filePath);
        _outputHelper.WriteLine("found: " + assembly?.GetName()?.Name);
        return assembly;
    }
    return null;
}
SabotageAndi commented 2 years ago

As we stopped maintaining the SpecFlow+ Runner (https://specflow.org/using-specflow/the-retirement-of-specflow-runner/) I am closing this issue.

github-actions[bot] commented 2 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.