How Visual Studio 2010 F5 Solution Deployment Works With SharePoint



Written by Chandrasekar Natarajan, Microsoft Premier Field Engineer.


Let’s say in Microsoft Visual Studio 2010 you create a new "ContentType" project by specifying the SharePoint site and solution type as farm solution. Inherit this new content Type from the Base Content Type of "Document",  then add the CustomField and CustomContentType xml files in the solution, as follows:

Elements.XML (CustomField)

 

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Field ID="{65600B98-5A04-4EC6-895B-E9A93CD17CC7}"

		   Type="Note"
		   Name="MyField"
		   DisplayName="My Field"
		   Group="CustomGroup"
		   NumLines="10"
		   Required="TRUE"/>
</Elements>

Elements.XML (CustomContentType)

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Parent ContentType: Item (0x01) -->
    <ContentType ID="0x01000f2eff1c776f425f90e10409eccc79c3"
                 Name="MyContentType"
                 Group="CustomContentTypeGroup"
                 Description="Custom Content Types"
                 Inherits="TRUE"
                 Version="0"
                 Overwrite="TRUE">
        <FieldRefs>

<FieldRef ID="{65600B98-5A04-4EC6-895B-E9A93CD17CC7}" Name="MyField"

DisplayName="My Field" Required="TRUE" />

        </FieldRefs>
    </ContentType>
</Elements>

Deploying the Content Using the F5 Key

Once the custom fields and custom content types are created, hit F5 to compile and deploy this Content Type in the SharePoint site. After the SharePoint site is displayed, we notice that the new content type exists in the Site.  Then  go back to VS2010, and hit Shift-F5 to stop debugging.  Now, again hit F5 to redeploy this Content type and it will fail with the following error message, Error occurred in deployment step 'Activate Features': The field with Id {65600B98-5A04-4EC6-895B-E9A93CD17CC7} defined in feature {a6192d76-512f-48de-9284-251b49902345} was found in the current site collection or in a subsite”

Now edit the elements.xml file, by changing the GUID, and set the Overwrite attribute to TRUE.  You will now be able to deploy and redeploy the solution over and over again.  The attribute “Overwrite” specifies whether the field definition for a new field that is activated on a site (SPWeb) overwrites the field definition for an existing field, in cases where the new field has the same field ID as the existing field. Hence when Overwrite is set to true, it assumes that the field already exists and it just overwrites the existing field.

<?xml version="1.0" encoding="utf-8"?> 
 <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> 
 <Field ID="{3de94b06-4120-41a5-b907-88773e493458}"
           Type="Note"
           Name="MyField"
           DisplayName="My Field"
           Group="CustomGroup"
           NumLines="10"
           Required="TRUE"
           Overwrite="TRUE"
           /> </Elements> 

So why do we see this behaviour?  Shouldn’t  Visual studio retract the fields when the solution is redeployed each time?  Actually, Visual Studio 2010 doesn't do the clean-up job. Visual Studio triggers a process named VSSPHost4.exe which does the job of adding and deploying the features. VSSPHost4.exe is a 64-bit host process that executes SharePoint commands, as outlined in the following post: http://msdn.microsoft.com/en-us/library/ee256704.aspx. This process doesn't refresh the SPSite/SPWeb objects.

The get around this problem we need to kill the VSSPHost4 process, as follows:

  1. F5 (Deploy the solution)
  2. Shift +F5 (Retract the solution)
  3. Again F5. This time it will fail.
  4. Open Task Manager and kill VSSPHost4 process.
  5. Now hit F5 and the solution gets deployed successfully.
Comments (0)

Skip to main content