提交 34808afa 编写于 作者: S Sam Harwell

Show code instead of designer if the designer is not installed

See dotnet/winforms-designer#458
上级 1cc7305d
......@@ -130,6 +130,10 @@ int IVsEditorFactory.Close()
// We must create the WinForms designer here
var loaderName = GetWinFormsLoaderName(vsHierarchy);
if (loaderName is null)
{
goto case "Code";
}
var designerService = (IVSMDDesignerService)_oleServiceProvider.QueryService<SVSMDDesignerService>();
var designerLoader = (IVSMDDesignerLoader)designerService.CreateDesignerLoader(loaderName);
......@@ -173,7 +177,7 @@ int IVsEditorFactory.Close()
return VSConstants.S_OK;
}
private static string GetWinFormsLoaderName(IVsHierarchy vsHierarchy)
private string GetWinFormsLoaderName(IVsHierarchy vsHierarchy)
{
const string LoaderName = "Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader";
const string NewLoaderName = "Microsoft.VisualStudio.Design.Core.Serialization.CodeDom.VSCodeDomDesignerLoader";
......@@ -193,6 +197,18 @@ private static string GetWinFormsLoaderName(IVsHierarchy vsHierarchy)
if (frameworkName.Identifier == ".NETCoreApp" &&
frameworkName.Version?.Major >= 3)
{
if (!(_oleServiceProvider.QueryService<SVsShell>() is IVsShell shell))
{
return null;
}
var newWinFormsDesignerPackage = new Guid("c78ca057-cc29-421f-ad6d-3b0943debdfc");
if (!ErrorHandler.Succeeded(shell.IsPackageInstalled(newWinFormsDesignerPackage, out var installed))
|| installed == 0)
{
return null;
}
return NewLoaderName;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册