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

Allow script extensions to declare unsafe blocks #1753

Merged
merged 3 commits into from
Apr 25, 2024

Conversation

PathogenDavid
Copy link
Member

The setting can be toggled by modifying Extensions.csproj, same as any other C# project.

This change also improves the robustness of the UseWindowsForms check since I modified it to use the helper I added for this change.

In particular it now only checks in appropriate locations within the project file, and perhaps more importantly it disregards the case of true vs True. At some point* Visual Studio started using the latter when these settings are changed via the UI, so anyone using it would've had True treated as false.

(*I assume so at least, I typically just modify my csproj by hand and I don't have an old version of Visual Studio to check at the moment–I would guess it changed when they redid the project configuration tool.)

Opening the whole project file to check a single value makes me slightly itchy, but it's consistent with similar logic in ScriptExtensions and I didn't want to get lost in the weeds refactoring.

Fixes #1727

This change also improves the robustness of the `UseWindowsForms` check, only checking in appropriate locations within the project file and disregarding the case of `true` vs `True`.
(The latter matters if someone uses the Visual Studio project editor, as it now uses `True` instead of `true`.)

Fixes bonsai-rx#1727
Copy link
Member

@glopesdev glopesdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PathogenDavid Looks great, I like the XPath solution and I definitely didn't know about the VS shenanigans with true vs True so thanks for calling that to attention.

I suggested a possible approach to refactor the XDocument business, simply because the file was already being opened twice in the current implementation. I had left it like this before pretty much for the same reasons to avoid a painful refactoring, but I guess third time's the charm as they say.

@glopesdev glopesdev added the fix Pull request that fixes an issue label Apr 23, 2024
@glopesdev glopesdev added this to the 2.8.3 milestone Apr 23, 2024
…sions` out into `ScriptExtensionsProjectMetadata`.

This better encapsulates this logic to avoid re-reading the `csproj` multiple times while avoiding changes to the external behavior of the interface over the lifetime of `ScriptExtensions` instances.
@PathogenDavid PathogenDavid requested a review from glopesdev April 25, 2024 03:22
@PathogenDavid
Copy link
Member Author

(Moved this out to a comment so it doesn't get lost when I resolve the conversation)

.Where(package => package is not null);

I know the old implementation had this, but is this actually a good thing to do? This basically means we couldn't figure out how to reference the requested assembly, should we throw instead?

@PathogenDavid PathogenDavid requested a review from glopesdev April 25, 2024 17:15
@glopesdev
Copy link
Member

This basically means we couldn't figure out how to reference the requested assembly, should we throw instead?

The logic behind it is that the compiler will warn about the missing assembly in context and that is usually enough to understand what is missing.

I agree it might be friendlier to stop earlier, in that case we would throw here and catch in the bootstrapper so we can print a friendly message similar to the compiler on this.

But I would maybe open a new issue to discuss this specific behaviour so we don't make this PR too big.

@glopesdev glopesdev merged commit d829231 into bonsai-rx:main Apr 25, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Pull request that fixes an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow script extensions to declare unsafe blocks
2 participants