title: Sharepoint 2010 - Add group on deploy
body: <p>in order to provide webparts and custom webtemplates for a site-collection, I need to create custom groups. I do that in the following way:</p>
  
  <pre><code>     using (SPSite site = properties.Feature.Parent as SPSite)
          {
              if (site != null)
                  using (SPWeb rootWeb = site.RootWeb)
                  {
  
                      try
                      {
                          rootWeb.AllowUnsafeUpdates = true;
                          rootWeb.SiteGroups.Add("Admins", site.Owner, site.Owner, "Admins");
  
                          try
                          {
                              SPGroup sp_grpAdmins = rootWeb.SiteGroups["Admins"];
                              SPRoleDefinition sp_rldAdmins = 
                              rootWeb.RoleDefinitions.GetByType(SPRoleType.Administrator);
                              sp_rldAdmins.Name = "Admin rights";
                              sp_rldAdmins.Description = "all";
                              rootWeb.RoleDefinitions.Add(sp_rldAdmins);
                              SPRoleAssignment sp_rlaAdmins = new SPRoleAssignment(sp_grpAdmins);
                              sp_rlaAdmins.RoleDefinitionBindings.Add(
                              rootWeb.RoleDefinitions["Admin rights"]);
                              rootWeb.RoleAssignments.Add(sp_rlaAdmins);
                              sp_grpAdmins.Update();
                              rootWeb.Update();
                          }
                          catch (ArgumentException argex)
                          {
  
                          }
          }
      }
  </code></pre>
  
  <p>If I add this code in a webpart (for debugging samples - can't get the event receiver to debug),
  the group gets created.
  Do you know how to either debug the feature event receiver or if there are limitations, that cannot be done in the feature event receiver?
  Thank you very much.</p>