Archive

Archive for October, 2011

Visual Studio Tip: Using SharePoint Site Url in Pre-Deployment and Post-Deployment scripts.

October 14, 2011 Leave a comment

Within Visual Studio 2010 SharePoint projects you might want to use the SharePoint Site Url that you have specified for your SharePoint project in Pre or Post Deployment scripts.

The SharePoint Site Url value can be retrieved using the $(SharePointSiteUrl) variable.

Usage

For example, this variable could be used in a pre-deployment script to deactivate certain features for the debug configuration.

To add the Pre Deployment script do the following:-

  • From Visual Studio 2010
  • Open your SharePoint Solution/Project
  • Click Project Properties
  • Click the SharePoint Tab
  • Add the following script to the Pre Deployment Script text box.
echo SiteUrl: $(SharePointSiteUrl)
if "$(ConfigurationName)" == "Debug" (
stsadm -o deactivatefeature -name "Feature1" -url $(SharePointSiteUrl) -force
stsadm -o deactivatefeature -name "Feature2" -url $(SharePointSiteUrl) -force
stsadm -o deactivatefeature -name "Feature3" -url $(SharePointSiteUrl) -force
stsadm -o deactivatefeature -name "Feature4" -url $(SharePointSiteUrl) -force
stsadm -o deactivatefeature -name "Feature5" -url $(SharePointSiteUrl) -force
)

Hope that helps.

For more information on Pre and Post-Deployment steps see this MSDN Link:

How to: Set SharePoint Deployment Commands (http://msdn.microsoft.com/en-us/library/ee231534.aspx)

 

U4FVW5JMFNEH

Visual Studio SharePoint Packaging Issue: Both "SharePointItem" and "SharePointItem" contains a file that deploys to the same Package location.

October 14, 2011 2 comments

I have had this problem a few times when moving and copying SharePoint SPI objects within Visual Studio 2010.

When you attempt to package and deploy your SharePoint solution the following error occurs:-

  • C:\TFSBulid\4\Project\BuildLocation\Sources\ProjectName\Package\Package.package: Both “[ExampleSiteDefinition]” and “[ExampleSiteDefinition]” contain a file that deploys to the same Package location: [Location]

The problem occurs because two of the SharePoint Project Item (SPI) have references to the same location. This seems to occur when you copy SharePoint Project Items.

If you take a look at the SharePointProjectItem.spdata file for the SharePoint Project Item that you copied from the SharePoint Point Item specified in the [Location] portion of the error message you will see that the SharePointProjectItem.spdata file will show details of the old SharePoint Project Item rather then the new SharePoint Item.

The content of the SharePointProjectItem.spdata looks like this:-

 1: <?xmlversion="1.0"encoding="utf-8"?>
 2: <ProjectItemType="Microsoft.VisualStudio.SharePoint.SiteDefinition" DefaultFile="onet.xml" SupportedTrustLevels="FullTrust" SupportedDeploymentScopes="Package"
 3: xmlns=http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel>
 4: <Files>
 5: <ProjectItemFileSource="default.aspx" Target="SiteTemplates\ExampleSiteDefinition\"
Type="TemplateFile" />
 6: <ProjectItemFileSource="onet.xml" Target="SiteTemplates\ExampleSiteDefinition\Xml\"
Type="TemplateFile" />
 7: <ProjectItemFileSource="webtemp_ExampleSiteDefinition.xml" Target="1033\XML\"
Type="TemplateFile"/>
 8: </Files>
 9: </ProjectItem>

To fix this update the ProjectItemFileSource element’s Target attribute to point to the correct location.

%d bloggers like this: