locked
Designer file (.designer.cs) not generated for a custom project (with extension .cw) in VS 2015 RRS feed

  • Question

  • Hi there,

    We've an integration to Visual Studio in our project using a VSPackage developed in VS 2005 that creates a custom project with its own editor using our own templates. The integration is working fine in VS 2005, and with some changes in VS 2010 and 2012. But now when we are upgrading the integration support to VS 2015, everything seems to be working fine except for the generation of the designer file (.designer.cs) for the custom project in VS 2015 IDE. As there's no designer file generated, controls dropped on to the editor of custom project are failing to generate the behind code which is causing the integration functionality to fail and making it useless. After investigating for a while came to know from the link http://www.visualstudioextensibility.com/category/vs14/ that VS extensibility is greatly changed in VS 2015 - especially, the code model and its generation implementation is now implemented as part of "Roslyn" platform which earlier used to be part of VS SDK. In this regard, I would like to know the changes we need to make in our VSPackage to see that the designer file which contains code behind is generated successfully so that our custom project in VS 2015 functions well.

    Thanks in advance for the help!

    Regards,

    Rama

    Wednesday, February 3, 2016 4:43 AM

Answers

  • How exactly is file.FileCodeModel failing? Is the file variable not being initialized correctly? I don't know anything about that particular codebase, but I can tell you the ProjectItem.FileCodeModel is still appears to be there in VS 2015.

    As a simple test, I created a new package with a custom command (added to the project item's context menu):

          <Button guid="guidNewCodeFilePackageCmdSet" id="NewCodeFileId" priority="0x0005" type="Button">
          <Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_ITEM_VIEW"/>
            <Strings>
              <ButtonText>Add Child Code File</ButtonText>
            </Strings>
          </Button>

    And then implemented the corresponding MenuItemCallback method as follows, and that worked as expected. So I suspect you may need to trace back further and see how you are retrieving that ProjectItem interface.

            private void MenuItemCallback(object sender, EventArgs e)
            {
                DTE dte = (DTE)Package.GetGlobalService(typeof(SDTE));

                IVsMonitorSelection vsMonSel = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection));
                IntPtr ppHier, ppSC;
                uint pitemID;
                IVsMultiItemSelect ppMIS;

                int hr = vsMonSel.GetCurrentSelection(out ppHier, out pitemID, out ppMIS, out ppSC);
                if (ppHier!=IntPtr.Zero)
                {
                    IVsHierarchy vsHier = null;

                    try
                    {
                        vsHier = (IVsHierarchy)Marshal.GetObjectForIUnknown(ppHier);
                    }
                    finally
                    {
                        Marshal.Release(ppHier);
                    }

                    if (vsHier!=null)
                    {
                        object objExtObj;
                        vsHier.GetProperty(pitemID, (int)__VSHPROPID.VSHPROPID_ExtObject, out objExtObj);
                        ProjectItem projItem = objExtObj as ProjectItem;
                       
                        if (projItem!=null)
                        {
                            System.Diagnostics.Debug.WriteLine(projItem.Name);

                            FileCodeModel fileCM = projItem.FileCodeModel;
                            if (fileCM != null)
                            {
                                System.Diagnostics.Debug.WriteLine(fileCM.Language);
                            }
                        }
                    }
                }
            }

    Sincerely,


    Ed Dore

    • Proposed as answer by DotNet Wang Monday, February 22, 2016 5:19 AM
    • Marked as answer by DotNet Wang Monday, March 7, 2016 2:30 AM
    Friday, February 19, 2016 5:50 AM

All replies

  • Hi Rama,

    Thank you for your post.

    >>I would like to know the changes we need to make in our VSPackage to see that the designer file which contains code behind is generated successfully so that our custom project in VS 2015 functions well.

    Documents on MSDN for your reference.

    https://msdn.microsoft.com/en-us/library/bb166329.aspx

    Samples which related to design on github.

    https://github.com/Microsoft/VSSDK-Extensibility-Samples/tree/master/WPFDesigner_XML

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 4, 2016 9:27 AM
  • Hi Li,

    Thanks for your response and the links provided for reference.

    I am basically looking for a workaround/solution on how to get designer file and its code behind generated for a custom project with extension(.cw) created in VS 2015 IDE. As I mentioned already we've implemented a VSPackage for this custom project and its designer file generation which is working fine in VS 2005/2010/2012. But in VS 2015, the project creation is successful, but the designer file generation is failing because that functionality is now moved to "Rosyln" platform. Below is the code used in our VSPackage for generation of the designer file.

    using System;
    using Captaris.Workflow.Designer.CodeGen;
    using Captaris.Workflow.Designer.Hierarchy;
    using Captaris.Workflow.Designer.VisualStudio.Hierarchy;
    using EnvDTE;
    using EnvDTE80;
    using Solution=Captaris.Workflow.Designer.VisualStudio.Hierarchy.Solution;

    namespace Captaris.Workflow.Designer.VisualStudio
    {
    public class HierarchyFactory
    {
    [CLSCompliant(false)]
    public static ISolution CreateSolution(DTE2 dte)
    {
    return new Solution(dte);
    }

    public static IProject CreateProject(DTE2 dte, Project project)
    {
    if (project.CodeModel == null)
    return null;

    if (project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp)
    return new CSharpProject(dte, project);

    if (project.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVB)
    return new VbProject(dte, project);

    return null;
    }

    internal static IFile CreateFile(DTE2 dte, Project project, ProjectItem file, Language language)
    {
    if (file.FileCodeModel == null)
    return new File(dte, project, file, language);

    if (file.FileCodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp)
    return new CSharpFile(dte, project, file, language);

    if (file.FileCodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVB)
    return new VbFile(dte, project, file, language);

    return null;
    }

    internal static ICodeClass CreateCodeClass(ProjectItem file, CodeClass codeClass)
    {
    if (file.FileCodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVB)
    return new VbCodeClass(file, codeClass);

    return new CodeGen.CodeClass(file, codeClass);
    }
    }
    }

    The designer file creation is failing at the lines highlighted in bold throwing an unhandled E_FAIL COM exception.

    I would like to know the changes to be made in our code for successful generation of the designer file. 

    Regards,

    Rama

     
    Monday, February 8, 2016 6:36 AM
  • Hi there,

    Request someone to please guide me on this.

    Thanks,

    Rama

    Tuesday, February 16, 2016 4:36 AM
  • What specifically is failing? The file.FileCodeModel, or the new File statement?

    Thanks,


    Ed Dore

    Thursday, February 18, 2016 1:51 AM
  • Hi Ed,

    It's the file.FileCodeModel that is failing.

    Thanks,

    Ramakrishna

    Thursday, February 18, 2016 11:25 AM
  • How exactly is file.FileCodeModel failing? Is the file variable not being initialized correctly? I don't know anything about that particular codebase, but I can tell you the ProjectItem.FileCodeModel is still appears to be there in VS 2015.

    As a simple test, I created a new package with a custom command (added to the project item's context menu):

          <Button guid="guidNewCodeFilePackageCmdSet" id="NewCodeFileId" priority="0x0005" type="Button">
          <Parent guid="guidSHLMainMenu" id="IDG_VS_CTXT_ITEM_VIEW"/>
            <Strings>
              <ButtonText>Add Child Code File</ButtonText>
            </Strings>
          </Button>

    And then implemented the corresponding MenuItemCallback method as follows, and that worked as expected. So I suspect you may need to trace back further and see how you are retrieving that ProjectItem interface.

            private void MenuItemCallback(object sender, EventArgs e)
            {
                DTE dte = (DTE)Package.GetGlobalService(typeof(SDTE));

                IVsMonitorSelection vsMonSel = (IVsMonitorSelection)Package.GetGlobalService(typeof(SVsShellMonitorSelection));
                IntPtr ppHier, ppSC;
                uint pitemID;
                IVsMultiItemSelect ppMIS;

                int hr = vsMonSel.GetCurrentSelection(out ppHier, out pitemID, out ppMIS, out ppSC);
                if (ppHier!=IntPtr.Zero)
                {
                    IVsHierarchy vsHier = null;

                    try
                    {
                        vsHier = (IVsHierarchy)Marshal.GetObjectForIUnknown(ppHier);
                    }
                    finally
                    {
                        Marshal.Release(ppHier);
                    }

                    if (vsHier!=null)
                    {
                        object objExtObj;
                        vsHier.GetProperty(pitemID, (int)__VSHPROPID.VSHPROPID_ExtObject, out objExtObj);
                        ProjectItem projItem = objExtObj as ProjectItem;
                       
                        if (projItem!=null)
                        {
                            System.Diagnostics.Debug.WriteLine(projItem.Name);

                            FileCodeModel fileCM = projItem.FileCodeModel;
                            if (fileCM != null)
                            {
                                System.Diagnostics.Debug.WriteLine(fileCM.Language);
                            }
                        }
                    }
                }
            }

    Sincerely,


    Ed Dore

    • Proposed as answer by DotNet Wang Monday, February 22, 2016 5:19 AM
    • Marked as answer by DotNet Wang Monday, March 7, 2016 2:30 AM
    Friday, February 19, 2016 5:50 AM
  • Ed,

    I agree with you that "file.FileCodeModel" is supported in VS 2015 and is working in a very generic way, but is failing with unhandled E_FAIL COM exception in our scenario when used in our custom project. I believe this is a project specific issue which needs to be investigated further opening a technical case.

    Thanks,

    Ramakrishna

     

    Friday, April 20, 2018 6:47 AM