Visual Studio 2010 F5 solution deployment

Create a content type project in Visual studio 2010 and then create some custom content types with some custom fields in it.

Sample Elements.xml file :

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <!-- Parent ContentType: Document (0x0101) -->
<Field ID="{D6A841D7-4067-4519-B794-E25AC438E9CF}"
  SourceID="" />
<ContentType ID="0x010100b19e17b94ee044778dcffe8f92ce18e6"
               Group="Custom Content Types"
               Description="My Content Type"
<FieldRef ID="{D6A841D7-4067-4519-B794-E25AC438E9CF}" Name="MyCustomField"/>

Now, Hit F5 to compile and deploy this Content Type.  First time deployment of the solution works fine, but subsequent deployment fails with this error message,

Error occurred in deployment step 'Activate Features': The field with Id {a6a841d7-4067-4519-b794-e25ac438e9cf} defined in feature {a6192d76-512f-48de-9284-251b49902345} was found in the current site collection or in a subsite.

We can get around this problem by setting the OverWrite property of the field to true, 

<Field ID="{D6A841D7-4067-4519-B794-E25AC438E9CF}"
  ... />

This works well because 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 need to overwrite this field.

What causes this exception?  Actually Visual Studio 2010 doesn't do the cleanup job. VS triggers a process named VSSPHost4.exe which does the job of adding, deploying the features.  VSSPHost4.exe is the 64-bit host process that executes SharePoint commands, This process doesn't refresh the SPSite/SPWeb objects.

The workaround to get rid of this exception is to kill the VSSPHost4 process

1. F5 (Deploy the solution)

2. Shift +F5 (Retract the solution)

3. Again F5.  This time it will fail.

4. Open the task manager and kill VSSPHost4 process.

5. Now F5 and the solution gets deployed successfully.

Ideally we need to kill the VSSPHost4 process any time we see the error message during the F5 deployment.

Comments (2)

  1. I picked up this tip from Doug Ware, a SharePoint consultant in Atlanta who authored a series of SharePoint tutorials:

    An alternate way to prevent field conflicts during development: put the following script calls in your Visual Studio pre-deploy command line box. These effectively drop and recreate the site. They run surprisingly quick, but, do add a few seconds more to your 'F5' rapid interative development cycles:

    stsadm -o deletesite -url devbox01.mycompany.local

    stsadm -o createsite -url devbox01.mycompany.local -owneremail -ownerlogin MYCOMPANYme -siteTemplate "STS#1" -description "This site is a Visual Studio test bed. It may get blasted away and recreated without notice." -title "My Development Site"

  2. Gerard says:

    Great explanation! Thanks

Skip to main content