Vs 2013 SharePoint visual webpart .ascx.g.cs file missing

During SharePoint 2013 visual webpart development, some time VS 2013 will miss or delete the .g.cs and during compilation, we may get the errors like “InitializeControl does not exist in current context” .

To generate a new webpartusercontrol.ascx.g.cs file we need to follow the below steps

1. Unload the SharePoint Project

2. Right click the project and Unload the project(Edit the .csproj file)

3. Find the webpart where the .g.cs file is missing

4. Check the below XML Tag in that place, if its missing or “LastGenOutput” is missing then add accordingly

<Content Include=”Webparts\WP_TestWebpart\WP_TestWebpart.ascx”>

5. Save the .csproj file and load the project

6. Now Right click on the .ascx file and Run the Custom Toll. (Make sure in the properties of ascx , customTool is SharePointWebPartCodeGenerator)

7. Now the webpart .g.cs file will be generated and we can compile without any errors

I hope this may help someone who struggle or delete the webpart again , to generate the .g.cs file 🙂

One thought on “Vs 2013 SharePoint visual webpart .ascx.g.cs file missing”

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 )

Connecting to %s