VS 11 Beta bug: EnvDTE80.Solution2.GetProjectTemplate(“ClassLibrary.zip”, “VisualBasic”) returns Windows Metro template

When running the unit tests of my MZ-Tools add-in today, I have found the following exception when creating a Class Library project:

System.Runtime.InteropServices.COMException (0x80042003): The project file ‘<omitted>’ cannot be opened.

The project type is not supported by this installation.
at Microsoft.VisualStudio.Windows.UI.Xaml.Project.ProjectFlavoring.TailoredLibraryProject.OnAggregationComplete()
at Microsoft.VisualStudio.Shell.Flavor.FlavoredProjectBase.Microsoft.VisualStudio.Shell.Flavor.IVsAggregatableProjectCorrected.OnAggregationComplete()
at EnvDTE.SolutionClass.AddFromTemplate(String FileName, String Destination, String ProjectName, Boolean Exclusive)
at Microsoft.VisualStudio.TemplateWizard.Wizard.Execute(Object application, Int32 hwndOwner, Object[]& ContextParams, Object[]& CustomParams, wizardResult& retval)
at EnvDTE.SolutionClass.AddFromTemplate(String FileName, String Destination, String ProjectName, Boolean Exclusive)

Debugging it I have found that the unit test was using the following template to create the project:

“C:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\ProjectTemplatesCache\VisualBasic\Windows Metro
style\1033\ClassLibrary.zipClassLibrary.vstemplate”

while in the past (using other VS versions and even VS 11 Developer Preview if I remember correctly) it was using:

“C:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\ProjectTemplatesCache\VisualBasic\Windows\1033\ClassLibrary.zipClassLibrary.vstemplate”

Notice that the former template belongs to “Windows Metro style” apps and the latter one belongs to “Windows” apps.

The unit test uses the following code to get the template:

EnvDTE80.Solution2.GetProjectTemplate(“ClassLibrary.zip”, “VisualBasic”)

and the root problem is that the “ClassLibrary.zip” template file name is duplicated in two folders, and therefore there is a conflict. According to the MSDN docs, templates should not duplicate names:

“Custom templates require unique file names that do not conflict with the file names defined in:

<drive>:Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\Language

The doc refers to custom templates, but obviously it assumes that built-in templates provided by Microsoft already use unique names.

So, I have opened a bug report in Microsoft Connect:

EnvDTE80.Solution2.GetProjectTemplate(“ClassLibrary.zip”, “VisualBasic”) returns Windows Metro template
https://connect.microsoft.com/VisualStudio/feedback/details/728382/envdte80-solution2-getprojecttemplate-classlibrary-zip-visualbasic-returns-windows-metro-template

The workaround is to hardcode portions of the path to templates in the unit tests, avoiding the Solution2.GetProjectTemplate method. UPDATE (05-JUL-2013): Apparently there is another workaround for the C# case using GetProjectTemplate(“csClassLibrary.vstemplate”, “CSharp”) instead. For VB.NET it doesn’t work because the template is named classlibrary.vstemplate and not vbClasslibrary.vstemplate.