The original Visual Web Part template is missing in Visual Studio 2012
By Anatoly Mironov
Today I encountered a weird issue, the classic Visual Web Part template was gone in Visual Studio 2012. When I created a Visual WebPart, a webpart was created with a generated .g.cs file, like the sandboxed visual webparts. I am not exactly sure why it happened. According to the MSDN guide Creating Web Parts for SharePoint, the structure of Visual Webparts should be the same as in Visual Studio 2010. It could have happened after I installed the power tools. However, if someone runs into the same issue, here is the solution: Copy this zip file from a computer with VS2010 installed:
C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\ItemTemplates\\CSharp\\SharePoint\\SharePoint14\\1033\\SharePoint14VisualWebPart.zip
Unpack it. Edit SharePointVisualWebPart.vstemplate
. Change the assembly line so it references to the Version 11:
<Assembly>Microsoft.VisualStudio.SharePoint.ProjectExtensions.Wizards, **Version=11.0.0.0**, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
```After that copy the directory `SharePoint14VisualWebPart` to these two locations on your computer with Visual Studio 2012 installed.
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\SharePoint\SharePoint14\1033\
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplatesCache\CSharp\SharePoint\SharePoint14\1033\
```Just to be safe, save the SharePoint14VisualWebPart
(which have the same name) by appending “.bak” to the name. If you don’t have an access to a VS2010 computer, I have saved the template for you on github.
Comments from Wordpress.com
Kiran - Sep 1, 2012
Thanks a bunch. I had the same problem with Visual Studio 2012 RC.
It is inside SharePointVisualWebPart.vstemplate
.
I am glad it helped. I could not find anything on google, so I shared this when I found a solution. First I thought i could be powertools. A collleague of mine ran into the same issue without powertools installed.
:) Glad it helped! I wonder why the original template is gone. Does Microsoft want us to abandon the usercontrol-inside-a-webpart-way, or is it just a miss?
Unpack it. Change the assembly line so it references to the Version 11: Where is this?? I`ve opened all files inside the zip and none has an similar text…
Thank you!!! Helped a lot, was adding my webparts with vs2010, saving, and re-opening in vs2012.
Anatoly, I will phrase this a little differently, but yes, we thought you would want to abandon the usercontrol-inside-a-webpart-way. Are there any benefits to it over the VS 2012 way?
Anatoly is spot-on - the new web part is pretty much the same as the Sandboxed Visual Web Part from Power Tools. The big advantage is that the new web part can be added to Sandboxed solutions in addition to the Farm solutions (and even published to Office365). Moreover, the end user experience of having two controls (web part and user control) is more complex and error-prone than having just one. I also know first hand that we only had that experience in the first place because of technical constraints that have been since overcome. That being said, maybe that approach had some unique strengths that the Visual Studio team has overlooked? If you want the original Visual Web Part back, please post a suggestion at http://connect.microsoft.com/ and articulate the reasons what are the features that are currently missing. We review all customer reports and suggestions on Connect and take it into account when making decisions for the next Visual Studio version. Iouri
Thank you for your input, Iouri! Now I use the new visual webparts.
Great discussion guys! =)
Thanks Dhanashri for the correction about SP 2013. I’ll adjust my blog post. But honestly, I abandoned this approach when I began developing for SP2013. As Iouri (in the comments above) said, with the new template you’ll get a more secure, faster and office 365-ready webpart.
That’s awesome post. you could solve my problem a big time. Thanks. only the correction is in file path location in SP 2013 environment: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\CSharp\Office SharePoint\1033 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplatesCache\CSharp\Office SharePoint\1033
Hi Iouri, As mentioned by Alex below this new change increases development time. Whereas before we just needed to copy the .ascx file to the hive to see our changes take affect now for every little UI change we need to build the assembly, deploy it to GAC and then recycle app pool and then wait for 10-30 seconds (depending on how powerful your development environment is) for the page to load up so that you can see your changes. Imagine repeating them 100’s of times every day and it turns into a really slow and painful process.
I agree that the new templates are less clumsy than earlier ones. however I’m not sure how the new templates are useful to implement the connectable web parts feature. as the new template doesn’t install the .ascx file in controltemplates gallery, but instead wrap all filed in the dll; we’ve no way to access the ascx file path control. do you have any thoughts on this?
Well. Dhanashri. I actually haven’t worked with connected webparts as much. As far as I know, the ascx isn’t so important in connected webparts.
Webpart development seemed easier with the old template because I could open up the .ascx file in the 14 hive to make small changes before committing those changes back to VisualStudio via copy/paste. That was easier than waiting for VisualStudio to retract, build, and redeploy the WSP just to test the effects of a simple HTML or javascript change.
I could get it worked. Thanks Anatoly.
Cool!
it worked, thank you.
Great Post ! Cheers
i have follow the same approach and it works but control.ascx.designer.cs file is missing. Please help how to fix it. thanks in advance.
I cannot answer this, because I have abandonned this approach. This template is not supported, as stated above by a MSFT employee (see comments). Sorry.
This approach worked a while, but it doesn’t seem to work anymore. As it is not supported, I have stopped using it. I hope you can find a solution. Please share then. Otherwise, we all should stop using this approach.
hello Anatoly Mironov. I need your help in one issue that i am facing with visual webpart in vst 2012 for SharePoint 2013. i have one solution file with two projects that i developed for SP 2010 in VST 2010. When i open thi in VST 2012 in SP 2013 server, it converts and shows some final messages and opens the solution. when i deploy and add the visual webpart, it says user control under control templates not found. even after manually copied to the required location (i.e., copied to 14/control templates/) i am getting the same error messagge. could u plz suggest what to do here. thank u.