-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Disable MEF services that are derived from VS services when executing in Blend #1651
Conversation
When current process is different to named process, set the MEF export's contract name to "GitHub.Disabled". Since this contract name isn't imported, the service is effectively disabled.
There's no need to specify a contract interface when exporting a property.
07f3dbe to
14c6fba
Compare
We should only load auto-load packages into the VS process (not Blend).
This attribute is used for conditionally export services when executing in the Visual Studio process. The `IsVisualStudioProcess` method can be used to check the availability of services exported in this way.
Commands should be disabled to avoid crashing Blend.
This stops the options pane from crashing Blend. I'm not sure how to hide the options completely in Blend.
|
For reference, here's what the MEF looks like when the extension is loaded in Blend: |
|
Tested this using Blend for VS 2015 and 2017. Can confirm that Blend no longer crashes or displays errors when trying to use/view GitHub functionality. Thanks @jcansdale ✨ One thing I find interesting is that even when the GitHub extension is disabled I still see these options in Blend:
|
Yes, this is unfortunately. Unfortunately there isn't an easy way to fix without degrading startup performance when the extension is running in Visual Studio. Here are some notes:
This button is default visible and loads the GitHubPackage when clicked.
I believe this command it also default visible and loads the GitHubPackage when clicked.
Don't think there's any support for dynamically enabling/disabling options. We could maybe show a warning dialog when the user clicks on one of those buttons saying the extension is only supported in VS? |
Show info message when AddConnectionCommand or ShowGitHubPaneCommand is executed inside Expression Blend.
Yes, I think it will. The user who originally reported the issue also commented on this: #1620 (comment) |

Since custom VS services are disabled in Blend, we need to disable any of our MEF services that are derived from VS services.
What this PR does
ExportForProcessAttributeso that when not executing in a specific named process the exportContractNameis set toGitHub.DisabledExportForVisualStudioProcessAttributeto conditionally export when executing in Visual Studio (devenv)IsVisualStudioProcessmethod to check when exports are availableUIContext_Gitwhen not running in Visual Studio processPreviously it was setting the
ContractTypetonullwhen not executing in the named process. This made it use the defaultContractTypeinstead of the explicit contract interface. This happened to work when[ExportForProcess(typeof(IFoo), "devenv")]was on classFoo, because the defaultContractTypewasFoonotIFoo. This didn't work when[ExportForProcess(typeof(IFoo), "devenv")]was on a property of typeIFoo, because the defaultContractTypewas exactly the same as the explicit contract interface.This this PR makes sets the
ContractNametoGitHub.Disablednot executing in the named process. Since we import using using [Import(typeof(IFoo))] rather than [Import("GitHub.Disabled", typeof(IFoo))], the service is effectively disabled. The disabled contract is given the unique nameGitHub.Disabledto avoid unlikely possibility of a collision.The following will still appear in the Blend UI:

When either of these buttons is clicked on, the following dialog will appear:

(not this has been changed from
Expression Blendto justBlend)The regression
This fixes a regression that appeared when I changed to using property based exports, e.g:
VisualStudio/src/GitHub.VisualStudio/GitHubPackage.cs
Line 126 in e4bf7e1
Previously only the following would have worked as intended.
Now the following will also work correctly:
What this PR doesn't do
There are some remnants that will still appear that are difficult to get rid of. The main thing is they won't crash Blend when clicked on!
Reviewers
Previously clicking on any of the remnants above would crash Blend.
@meaghanlewis this might be worth putting into the test plan...
Check that selecting any of the following doesn't crash Blend:
Other Widows > GitHubManage connections > Connect to GitHubOptions > GitHub for Visual StudioFixes #1620