Add an optional experimental feature that allows the VS extension to let the the discovered bindings written out to a file.#771
Conversation
… bindings to a JSON file for the Visual Studio extension.
|
Both the legacy connectors and this approach both run something out of process, right? I'm confused as to how this approach avoids assembly load conflicts while the existing approach has those problems. What is different that helps? |
|
Rather than dry-run a feature's worth of tests why not generate a pseudo-test (without test framework attributes) in each test assembly that can be invoked to trigger binding discovery? |
Because with this, the test runner (dotnet test) does the assembly loading, not our connector.
Yeah, we could do that, but that would be ugly as the pseudo-test would be also visible for the user. |
I was thinking in terms of an additional class added to the produced assembly not an additional method on each generated feature class. Something like the assembly using class. It's present and visible, yes, but not likely to bother anyone. |
It would, I know. |
|
I have reworked the PR and not use the formatter API for this. It is much simpler this way and easier to remove if not useful. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds an experimental feature that enables the Visual Studio extension to discover bindings through file output instead of loading test assemblies directly. This addresses assembly loading errors that occur when the VS extension tries to load and execute test assemblies.
Key changes:
- Introduces a new
IBindingProviderServiceinterface and implementation that can write discovered bindings to a JSON file - Adds environment variable support (
REQNROLL_BINDING_OUTPUT) to trigger binding file output during test runs - Integrates the binding provider service into the dependency injection container and binding registry building process
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
BindingProviderService.cs |
Adds new interface and implements binding output functionality with environment variable detection |
RuntimeBindingRegistryBuilder.cs |
Integrates binding provider service and calls it when building completes |
DefaultDependencyProvider.cs |
Registers the new binding provider service in the DI container |
BindingJsonSourceGenerator.cs |
Updates JSON serialization options to ignore null properties |
RuntimeBindingRegistryBuilderTests.cs |
Updates test constructor to include mock binding provider service |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
I have reqnroll vs2022 extension 2025.1.256 and dotnet 9.0.304 |
|
@meliyesil Please report it to https://github.com/reqnroll/Reqnroll.VisualStudio/issues |
⚡️ What's your motivation?
Provide an alternative way for the Visual Studio extension to discover the bindings without the need to load the test assembly and run code from it, that is potentially causing assembly loading errors, like reqnroll/Reqnroll.VisualStudio#97
🤔 What's changed?
Added
BindingProviderService.OnBindingRegistryBuildingCompleted(): A handler that can write the discovered bindings to a JSON file for the Visual Studio extension if instructed though an environment variable.Currently the VS extension loads the test assembly to a console app (e.g.
<extension>\Connectors\Reqnroll-Generic-net8.0\reqnroll-vs.exe, tries to resolve its dependencies (magic++) and then invoke theBindingProviderService.DiscoverBindingsmethod from the loaded assembly that returns a JSON string with the binding information. The connector does a bit of further processing on it (gets step definition source line numbers from PDB), and then returns it to the VS extension, so that it can properly display the binding info.This is performed after every successful build.
This sometimes causes assembly loading errors and requires a compilation of the console app for each .NET version.
The new concept would be the following:
dotnet test --no-build, by setting the environment variablesREQNROLL_DRY_RUN=trueandREQNROLL_BINDING_OUTPUT=truebefore.OnBindingRegistryBuildingCompletedwould split out the same JSON string that was produced byBindingProviderService.DiscoverBindingsto a file (reqnroll_bindings.json)Open questions:
How to make sure that the other formatters are not activated during this. Maybe we could extend the idea of Set individual formatters with key-value based environment variables #769 with something, likeREQNROLL_FORMATTERS_ALL=falsethat would disable all "other" formatters.Plan:
What do you think?
🏷️ What kind of change is this?
♻️ Anything particular you want feedback on?
📋 Checklist:
This text was originally taken from the template of the Cucumber project, then edited by hand. You can modify the template here.