Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Generators with Exposed MSBuild Properties #1188

Open
dansiegel opened this issue Sep 16, 2024 · 2 comments
Open

Testing Generators with Exposed MSBuild Properties #1188

dansiegel opened this issue Sep 16, 2024 · 2 comments

Comments

@dansiegel
Copy link

Description

Some Generators require access to MSBuild properties to have additional context to be able to properly generate. How can I inject values into the Generator Test so that the generator can access properties that would normally be provided from MSBuild:

context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.SomeProperty", out var value);
@Youssef1313
Copy link
Member

You can do it this way:

TestState.AnalyzerConfigFiles.Add(("/.globalconfig", """
    is_global = true
    build_property.SomeProperty = value
    """));

@dansiegel
Copy link
Author

thanks @Youssef1313 if that's in the docs I couldn't find it. That seems to have done the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants