Adding Web User Controls (.ascx) to WSPBuilder Project


I was working on a SharePoint webpart in Visual Studio 2005,  few days before, creating a WSPBuilder project. At one stage i wanted to add a web user control (.ascx file) to my project and make use of it in my webpart. So i right clicked the appropriate folder i want to place it in the 12 hive and chose add new item.

But i was not able to see a Web User Control item in the list of Add New Items. I tried a few items to add the item and then thought of an ugly idea of creating the ascx in another project and copying it into this project. Then i got this solution from an online article for adding web application items support to the wspbuilder project.

1. Right click the project and choose ‘Unload Project’ from the menu.

2. Right the project node in Solution Explorer and choose Edit ProjectName.csproj.

3. Look for the highlighted line in the .csproj file.

2 <PropertyGroup>

3 <Configuration Condition= ‘$(Configuration)’ == ” >Debug</Configuration>

4 <Platform Condition= ‘$(Platform)’ == ” >AnyCPU</Platform>

5 <ProductVersion>8.0.50727</ProductVersion>

6 <SchemaVersion>2.0</SchemaVersion>

7 <ProjectGuid>{375819D3-5E9F-41ED-B8A5-2888B82C2539}</ProjectGuid>

8 <OutputType>Library</OutputType>

9 <AppDesignerFolder>Properties</AppDesignerFolder>

10 <RootNamespace>SampleWSP</RootNamespace>

11 <AssemblyName>SampleWSP</AssemblyName>

12 <ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

13 <SignAssembly>true</SignAssembly>

14 <AssemblyOriginatorKeyFile>SampleWSP.snk</AssemblyOriginatorKeyFile>

15 <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

16 </PropertyGroup>

4. Add {349c5851-65df-11da-9384-00065b846f21} to the ProjectTypeGUIDs node.

2 <PropertyGroup>

3 <Configuration Condition= ‘$(Configuration)’ == ” >Debug</Configuration>

4 <Platform Condition= ‘$(Platform)’ == ” >AnyCPU</Platform>

5 <ProductVersion>8.0.50727</ProductVersion>

6 <SchemaVersion>2.0</SchemaVersion>

7 <ProjectGuid>{375819D3-5E9F-41ED-B8A5-2888B82C2539}</ProjectGuid>

8 <OutputType>Library</OutputType>

9 <AppDesignerFolder>Properties</AppDesignerFolder>

10 <RootNamespace>SampleWSP</RootNamespace>

11 <AssemblyName>SampleWSP</AssemblyName>

12 <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

13 <SignAssembly>true</SignAssembly>

14 <AssemblyOriginatorKeyFile>SampleWSP.snk</AssemblyOriginatorKeyFile>

15 <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>

16 </PropertyGroup>

5. Now right click the Project and choose ‘Reload Project’ and try adding a .ascx file.

You must get it now.

Note: Cross posted – http://blog.sharepointpowerpack.com/archive/2010/11/22/adding-web-user-controls-ascx-to-wspbuilder-project.aspx

NLV

About these ads

, ,

  1. #1 by Sreenath on April 11, 2010 - 11:38 am

    Hello

    Exactly what I was looking for. Thanks for this post. I would not have been able to get to this myself.

    A lesson I learned while doing this: The order of the ProjectTypeGuids does matter and the GUID mentioned in this post better be first for it to work or you will get an error while reloading the project.

    Thanks
    Sreenath

  2. #2 by nlvraghavendra on April 11, 2010 - 4:44 pm

    Hmm, I guess i got it right by having the GUIDs in the order i mentioned in the post. Let me do a recheck again.

    NLV

  3. #3 by Sreenath on April 11, 2010 - 5:40 pm

    Yes, you have it right in your illustration, not a problem.

    I got it wrong by adding the GUID you’ve given to the end of my existing project type GUID’s and that gave me the trouble.

    Cheers

  4. #4 by Tyler on May 6, 2010 - 2:24 am

    I tried repeating this using VS 2008 with a SharePoint Web Part project… although the differences seemed small (an extra GUID in the ProjectTypes list), the option to add a User Control was still unavailable. Any ideas?

  5. #5 by nlvraghavendra on May 6, 2010 - 7:15 pm

    Did you add the GUID before the others as Sreenath mentioned?

  6. #6 by lakshmi on May 14, 2010 - 6:01 am

    I am getting error while reloading the project if i add GUID which was specified by sreenath the error desc is “The project type is not supported by this installation” please help me out regarding this

  7. #7 by nlvraghavendra on May 15, 2010 - 6:18 pm

    Can you tell me what versions of Visual Studio and WSP Builder you are using?

  8. #8 by Sreenath on May 15, 2010 - 8:28 pm

    Lakshmi

    Try unloading/removing the project from the solution in visual studio, close Visual Studio, reopen the solution and then add the specific project to the solution.

    I faced the same sort of errors but doing some combination of actions like the above (unload-reload) got it working and haven’t had any trouble after that.

    Not sure what’s the exact issue but I didn’t really crack my head on it once it started working.

    I am using VS2008.

    Hope that helps.

    Cheers
    Sreenath

  9. #9 by Guy on August 9, 2010 - 7:17 pm

    I am using vs2008 and do not have the in my .vbproj file. So I can’t change it.

    • #10 by nlvraghavendra on August 10, 2010 - 5:38 pm

      Hello Guy

      I cant get you. What is missing from your .vbproj?

  10. #11 by chirantan on June 15, 2011 - 8:32 am

    Hi ,

    This is really very good example and it works. But unfortunately this is not compiling .cs file with dll. That is the reasonwhen ascx file is loaded in any page it is not finding it’s type(class). e.g.
    here page is not able to find class .iDotResult and looks it is not compiled with wspbuilder project.

    can any one help me on this.

    Thanks,
    Chirantan
    chirantan.upadhyay@igt.in

    • #12 by nlvraghavendra on June 15, 2011 - 9:40 am

      I would recommend you to get the latest version of WSPBuilder which supports both SharePoint 2007 and SharePoint 2010 and also supports adding web project items into the project. Moreover I think you are having a type mismatch. This has nothing to do with the WSPBuilder.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: