locked
Project System: How to debug when new project is not displayed RRS feed

  • Question

  • Hi,

    I am developping under VS2010 on Windows 7 a Visual Studio add-in to provide support for a language called ObjectiveJ (Objj).
    For the moment I have already developped the language service with syntax highlighting and now I would like to add a basic project system .

    The project is splitted as shown below: 


    And the assembly Smi.VisualStudio.Language.Objj has the following structure :

    To implement this custom project I followed the following guide : http://msdn.microsoft.com/fr-fr/library/cc512961.aspx and it works fine.

    But now I would like more control over what is displayed and I would like to use the "vstemplate" methode described in the part 2 of the guide quoted above (see http://msdn.microsoft.com/en-us/library/cc826178(v=vs.100).aspx)

    So here is what I have declared for my project class :

    [PackageRegistration(UseManagedResourcesOnly = true)]
    	//[DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\10.0Exp")]
    	[ProvideObject(typeof(GeneralPropertyPage))]
    	[ProvideProjectFactory(typeof(ObjjProjectFactory), 
            "Objj", 
            "Objj Project Files (*.objjproj);*.objjproj",
            "objjproj", "objjproj",
            ".\\NullPath",
            //@"Templates\Projects\ObjjProject",
            LanguageVsTemplate = "Objj")]
        [Guid("BBA1C3DE-5112-4F1C-80C5-A9A618EC71CA")]
    	public sealed class CustomProjectPackage : ProjectPackage
    	{
    		#region Overridden Implementation
    		/// <summary>
    		/// Initialization of the package; this method is called right after the package is sited, so this is the place
    		/// where you can put all the initilaization code that rely on services provided by VisualStudio.
    		/// </summary>
    		protected override void Initialize()
    		{
    			base.Initialize();
    			this.RegisterProjectFactory(new ObjjProjectFactory(this));
    		}
    
    		public override string ProductUserContext
    		{
    			get { return "ObjjProj"; }
    		}
    
    		#endregion
    	}

    As you can see I have commented the @"Templates..." and replaced it by ".\\NullPath" and I have added a .vsct file with the following content :

    <?xml version="1.0" encoding="utf-8" ?>
    <CommandTable
      xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable">
    </CommandTable>

    To be continued...

    Friday, September 7, 2012 8:52 PM

Answers

  • Ok I found by looking at IronPython sample code, I have added the following line to source.extension.vsixmanifest :

     <ProjectTemplate>Templates\Projects\ObjjProject</ProjectTemplate>

    and now it works.

    I must say that building a Visual extension is not that easy and information that can be found on the msdn is incomplete or wrong.

    • Marked as answer by Vincent Rich Saturday, September 8, 2012 9:53 AM
    Saturday, September 8, 2012 9:53 AM

All replies

  • And I have edited the vsproj to set the VSCTCompile as Build Action.

    About the Templates file structure I get this :

    However when I click on debug to deploy on the experimental instance and I select New Project I dont' see my custom project.

    If I check the extension folder inside AppData I get the following files :

    So now what I am doing wrong ? How can I debug and find why my new project doesn't appear when I want to create a new project ?

    Friday, September 7, 2012 8:55 PM
  • VSCT has nothing to do with projects, it has to do with commands. You don't need one here that I can see.  Have you run /setup?  The template tree is cached in VS, if VS doesn't know new templates have shown up they won't be visible as they won't exist in the cache.

    Ryan

    Friday, September 7, 2012 9:44 PM
  • From the guide http://msdn.microsoft.com/en-us/library/cc826178(v=vs.100).aspx we can read

    "Visual Studio must be run in setup mode to recognize a new or modified Visual Studio template. Setup mode requires a .vsct file to be present. Therefore, you must add a minimal .vsct file to the project."

    and also

    "The VSPackage project build system typically runs Visual Studio in setup mode when the .vstemplate file is changed or the project that contains the .vstemplate file is rebuilt. You can follow along by setting the verbosity level of MSBuild to Normal or higher."

    That's why I have added . vsct file but it doesn't seem to work because I cannot see in the detailed log the line :

    Target SettingUpDevenv:
        \\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.com 
            /rt "Software\Microsoft\VisualStudio\10.0Exp" /setup 

    So I tried to add /setup to the command line arguments inside the Debug property page but I get the following error message :

    The operation could not be completed. Access denied.

    Do I need to be admin ?

    When I look at IronPython project it seems to work automatically without having to run /setup and the template cache is built the first time I click on New Project...



    • Edited by Vincent Rich Saturday, September 8, 2012 9:06 AM
    • Marked as answer by Vincent Rich Saturday, September 8, 2012 9:44 AM
    • Unmarked as answer by Vincent Rich Saturday, September 8, 2012 9:44 AM
    Saturday, September 8, 2012 8:59 AM
  • Ok I found by looking at IronPython sample code, I have added the following line to source.extension.vsixmanifest :

     <ProjectTemplate>Templates\Projects\ObjjProject</ProjectTemplate>

    and now it works.

    I must say that building a Visual extension is not that easy and information that can be found on the msdn is incomplete or wrong.

    • Marked as answer by Vincent Rich Saturday, September 8, 2012 9:53 AM
    Saturday, September 8, 2012 9:53 AM
  • "Visual Studio must be run in setup mode to recognize a new or modified Visual Studio template. Setup mode requires a .vsct file to be present. Therefore, you must add a minimal .vsct file to the project."

    You seem to have an unerring faith in the correctness of MSDN :)  Mistakes can be made in documentation just like mistakes can be made in code. The above is 100% incorrect, I will file a bug for the documentation folks to fix it.

    When I look at IronPython project it seems to work automatically without having to run /setup and the template cache is built the first time I click on New Project...

    I know nothing about the IronPython sample but in general when things 'just work' it means someone has done the work to automate the necessary steps. Generally this is why people trying to hand hack their existing projects to include new bits and pieces doesn't work well since they inevitably don't add all the stuff they need to get it to 'just work'.

    Ryan

    Saturday, September 8, 2012 4:52 PM
  • I don't know if there is a specific 'how do I manually add a new project template to an existing project' kind of tutorial, that isn't the mainline case so it likely doesn't have a walkthrough.

    The most important thing to know is how VSIX works. That is rather extensively documented here.  

    The most important part, for this situation, is this, specifically the 'List of Assets' section.

    VSIX files have to explicitly declare the kind of content they contain, which is why adding the ProjectTemplate tag by hand (this is normally done via the VSIX designer) worked.

    Unfortunately for things like this there is no way to give a run-time diagnostic because the experimental instance can't, for instance, warn that something is missing when you haven't take the steps to inform it that that something should be there in the first place.

    > must say that building a Visual extension is not that easy

    It can be tricky, then again I have never had the experience of doing serious extensibility on any platform (Windows, *nix, Eclipse, etc..) that wasn't equally difficult. Most people that claim X is so much easier are really claiming 'I have been doing X for Y years', which of course makes something seem much easier, as you have already gone through the painful learning process. This is generally known as the Curse of Knowledge.

    Ryan

    Saturday, September 8, 2012 5:02 PM