Showing posts with label Deployment. Show all posts
Showing posts with label Deployment. Show all posts

Saturday, January 26, 2013

Refresh GAC using Powershell

Scenario:
Refreshing GAC is always a painful thing.
Do IISReset / remove old stuff / put new one. Can we automate it ?

Solution:
Certainly.. mighty power-shell can do it easily

If you are running on new machine - you might need to relax executing policy

Set-ExecutionPolicy Unrestricted
Code:
iisreset /stop

Set-Alias Gacutil "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\gacutil.exe"

Gacutil /uf EntLibContrib.Data.OdpNet
Gacutil /i "MS ENT dlls\EntLibContrib.Data.OdpNet.dll"

Gacutil /uf Microsoft.Practices.EnterpriseLibrary.Caching
Gacutil /i "MS ENT dlls\Microsoft.Practices.EnterpriseLibrary.Caching.dll"

Gacutil /uf Microsoft.Practices.EnterpriseLibrary.Common
Gacutil /i "MS ENT dlls\Microsoft.Practices.EnterpriseLibrary.Common.dll"

Gacutil /uf Microsoft.Practices.EnterpriseLibrary.Data
Gacutil /i "MS ENT dlls\Microsoft.Practices.EnterpriseLibrary.Data.dll"

Gacutil /uf Microsoft.Practices.EnterpriseLibrary.Logging
Gacutil /i "MS ENT dlls\Microsoft.Practices.EnterpriseLibrary.Logging.dll"

Gacutil /uf Microsoft.Practices.ServiceLocation
Gacutil /i "MS ENT dlls\Microsoft.Practices.ServiceLocation.dll"

Gacutil /uf Microsoft.Practices.Unity.Configuration
Gacutil /i "MS ENT dlls\Microsoft.Practices.Unity.Configuration.dll"

Gacutil /uf Microsoft.Practices.Unity
Gacutil /i "MS ENT dlls\Microsoft.Practices.Unity.dll" 

Gacutil /uf Microsoft.Practices.Unity.Interception.Configuration
Gacutil /i "MS ENT dlls\Microsoft.Practices.Unity.Interception.Configuration.dll"

Gacutil /uf Microsoft.Practices.Unity.Interception
Gacutil /i "MS ENT dlls\Microsoft.Practices.Unity.Interception.dll" 

Gacutil /uf Telerik.Web.Design
Gacutil /i "Telerik.Web.Design.dll"

Gacutil /uf Telerik.Web.UI
Gacutil /i "Telerik\Telerik.Web.UI.dll" 

Gacutil /uf Telerik.Reporting
Gacutil /i "Telerik\Telerik.Reporting.dll"

Gacutil /uf Telerik.Web.UI.Skins
Gacutil /i "Telerik\Telerik.Web.UI.Skins.dll"

iisreset /start

Monday, December 12, 2011

Powershell and search metadata properties

Scenario:
While working with one of client we created a quick script for creating / recreating metadata properties for search. Thought of sharing :)

This script will drop exiting property with same name [ if exist ] and create it again. Also I have provided samples of different field types.

Code:


#####################################################################
# Main Function
#####################################################################

function PromptUser {param($message)

write-host -f Red $message

write-host -f Red "Press enter to continue ... and N to exit"

$keyentered = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

If ($keyentered.VirtualKeyCode -eq 78)
{
exit
}
}

function DropMetadataProperties {param ($ServiceApplicationName, $MetadataPropertyName)

$category = Get-SPEnterpriseSearchMetadataCategory –Identity "Business Data" -SearchApplication $searchapp

If (Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $MetadataPropertyName -ea "silentlycontinue")
{
write-host -f Green "MetaProperty already exists, we delete it so it can be reacreated."
$prop = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $MetadataPropertyName
$prop.DeleteAllMappings()
$prop.Delete()
$searchapp.Update()
}

if (!$?)
{
PromptUser("An error has occurred")
}
}

function CreateMetadataProperties {param ( $ServiceApplicationName, $MetadataPropertyName, $CrawledProperty, $VariantType, $Type, $HasMultipleValues, $IsSortable)

$category = Get-SPEnterpriseSearchMetadataCategory –Identity "Business Data" -SearchApplication $searchapp

$crawledproperty = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $category -VariantType $VariantType -Name $CrawledProperty
If (!($crawledproperty -eq $null))
{
$managedproperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $MetadataPropertyName -Type $Type

If ($IsSortable -eq $True)
{
$managedproperty.MaxCharactersInPropertyStoreIndex = 64
$managedproperty.Update()
}

If ($HasMultipleValues -eq $True)
{
$managedproperty.HasMultipleValues = $true
$managedproperty.Update()
}


New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty
}
else
{
write-host -f Red "Crawl property is missing, you might need to recrawl your content source to get it."
}

if (!$?)
{
PromptUser("An error has occurred")
}
}

###################################################################################
# Drop metadata properties
###################################################################################

$searchapp = Get-SPEnterpriseSearchServiceApplication
if (!$?)
{
PromptUser("Could not find a valid Search Service Application.")
EXIT
}

$searchAppName = $searchapp.Name


# Client Metadata properties
DropMetadataProperties $searchAppName "xxClientName"

###################################################################################
# Create metadata properties
###################################################################################

# VariantType = (31 for string , 20 for integer , 11 for boolean , 64 for datetime )
# Type = (1 for string , 2 for integer , 5 for Yes/No , 4 for datetime )

### Text Field
DropMetadataProperties $searchAppName "xxClientName"
CreateMetadataProperties $searchAppName "xxClientName" "Client.ClientName" 31 1 $False $True

### Integer Field
DropMetadataProperties $searchAppName "xxClientID"
CreateMetadataProperties $searchAppName "xxClientID" "Clients.ClientID" 20 2 $False $False

### YES/No Field
DropMetadataProperties $searchAppName "xxIsActive"
CreateMetadataProperties $searchAppName "xxIsActive" "Clients.IsActive" 11 5 $False $False

### Date Field
DropMetadataProperties $searchAppName "xxEndDate"
CreateMetadataProperties $searchAppName "xxEndDate" "Clients.EndDate" 64 4 $False $False
Please do leave comments on if it worked for you or any suggestion to improve it.

Monday, October 31, 2011

Error in Activate Features from Visual Studio

Scenario:
I was re-deploying a solution from Visual Studio. My solution had custom Fields / Content Type declarations and was getting deployed to an existing site collection.

I noticed following errors :

Error occurred in deployment step 'Activate Features': The field with Id {GUID} defined in feature {GUID} was found in the current site collection or in a subsite.

OR

Error occurred in deployment step 'Activate Features': The content type with Id {GUID} defined in feature {GUID} was found in the current site collection or in a subsite.

Reason:
First of all this is not a problem with Solution. As if you use STSADM / Powershell to deploy and activate features, it will work fine.

Actually there is something going on with VSSPHost4 process.

Solution:
There are 2 solutions to this issue.

1. Close the Visual Studio and start again :)

2. Kill VSSPHost4 process. This can be done from SharePoint Powershell Management shell command prompt

stop-process -processname vssphost4 -force

Tuesday, April 19, 2011

SP2010 : Powershell deployment

Scenario:
We need this all the time to retract / remove / add / deploy solution.Want to know what I use ?

Solution:
Powershell

Script:

####################################################################################################
# Function
####################################################################################################

function RetractAndRemoveSolution {param ($SolutionPackageName, $DeployedGlobally)
$solution = Get-SPSolution | where-object {$_.Name -eq $SolutionPackageName}

# check to see if solution package has been installed
if ($solution -ne $null)
{
if($solution.Deployed -eq $true)
{
if( $DeployedGlobally -eq $true)
{
Uninstall-SPSolution -Identity $SolutionPackageName -Local -Confirm:$False
}
else
{
Uninstall-SPSolution -Identity $SolutionPackageName -AllWebApplications -Local -Confirm:$False
}
}

Remove-SPSolution -Identity $SolutionPackageName -Confirm:$false
}
}

###########################################################################################
# To uninstall/remove custom solutions in central administration.
###########################################################################################

Write-Host "Removing solutions"

RetractAndRemoveSolution "CustomSolution.wsp" $false
RetractAndRemoveSolution "CustomSolutionGlobal.wsp" $true

###########################################################################################
# To add/deploy custom solutions in central administration.
###########################################################################################

Write-Host "Adding Solutions"

$currentfolder = (Get-Location -PSProvider FileSystem).ProviderPath
Add-SPSolution -LiteralPath $currentfolder"\CustomSolution.wsp"

###########################################################################################
# To deploy custom solutions to newly created site collection
# ( Mainly for use in DEV only, recommended to deploy using Central Admin UI for other environments )
###########################################################################################

Write-Host "Installing Solutions"

$webInsite = "http://intranet.contoso.com"
Install-SPSolution -Identity "CustomSolution" –WebApplication $webInsite –GACDeployment

###########################################################################################
# Reset IIS / Restart Services / Exit to ensure not binary is locked with Powershell Editor
###########################################################################################

iisreset

net stop "Sharepoint Server Search 14"
net start "Sharepoint Server Search 14"

exit

Wednesday, December 15, 2010

SharePoint Administration service (spadminV4),

Error:
This operation uses the SharePoint Administration service (spadminV4), which could not be contacted.

Or

An unexpected internal error occurred in the Business Data Connectivity Shared Service: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


Got the above error while deploying / redeploying new WSP

Reason:
Basically its a clear cut indication that the one of the required service is un-reachable.

Solution:
There are few things I will recommend you trying

1. Reset all servers in the farm and try once more.

2. Are you trying to deploying using command line , then try UI or vice-versa

3. Login to each box and start services management console. Look for SharePoint Administration service (spadminV4) on each box and restart it. Please make sure to do this on all servers in farm even though you got error on 1 server.

4. This is workaround to kick off jobs without depending upon the failing service, but you can use OLD STSADM command ( stsadm -o execadmsvcjobs ) . Run it on the failing server or all the servers.

5. Also you might have look into Timer Jobs ( waiting mode ). SharePoint creates one timer job for each server. If you see any such job related to Deployment waiting for long time. Delete the job and try redeploying.

Other related posts:
Deployment stuck at retracting message , Deployment stuck at retracting message

Wednesday, September 30, 2009

The solution file located at "xxxx.wsp" does not appear to be a valid upgrade

Scenario:
You got the following error while using the upgrade command with your updated solution file.

Error : The solution file located at "xxxx.wsp" does not appear to be a valid upgrade for solution "xxxx.wsp".
The two solutions must have the same resource types (global or Web-application scoped).


Reason:
This can be due to change in feature scope or addition of a new feature in the solution package from its previous version.

SharePoint is complaining by saying that the solution was either deployed Globally last time and this time you are trying to deploy it to a specific Url or the other way around.

Solution:
I will suggest to better retract/delete the old solution and add/deploy the new one.

But just in case you have issues with this approach, I will suggest to compare the features in the solution package and move it to another solution package.

Comments welcome...

Friday, September 4, 2009

Deployment command issues

Scenario:
This is one of the common issues I have seen with people developing solution on single WFE server farm and deploying sharepoint solution to multi-server WFE farm.

"The solution has not been deployed and may require clean up"

Reason:
Though there can be several issues, I am pointing out few here.

1. STSADM -o execadmsvcjobs
Often this command is used after retract solution and deploy solution command. This command executes all administrative timer jobs immediately instead of waiting for the timer job to run. Think of it as a console application with the same code as of Timer Job, only thing is it will run instantly. So far so good. But assuming that this means it has executed the job on all server is not true, which can be very problematic in multi-server farm.

Common Error: The solution-deployment-trainingwebparts.wsp-0 job completed successfully, but could not be properly cleaned up. This job may execute again on this server.

Recommendation : Wait for timer job to execute the deployment/retracting jobs and not to use it at all in deployment /retracting scripts in multi-server farm.

2. IISReset / Application Pool Reset
This command basically restarts the IIS services which is required to make sure web.config / GAC and other XML file based changes done on the file system get picked up.

Recommendation : Make sure you reset IIS / Application pool on all the WFEs

3. Resetting Timer service
net stop "Windows Sharepoint Services Timer"
net start "Windows Sharepoint Services Timer"

This command basically restarts the Timer services, which is required to make sure it picks up the code changes done to Custom Timer Job.

Recommendation : Make sure you reset Timer job on all the WFEs

4.Feature Activation:
Try to keep these commands in separate file or add 30sec pause between deploy solution and feature activation , other you might get error complaining feature is not installed ( on another server ).

Recommendation : Use separate file for these kind of commands.

5.Use of Force attribute:
Lot of times we use Force attribute as a rule of thumb.. :-) , try to understand the need of this attribute.

As per MSDN , using it in UninstallFeature forces an installation of a feature that is already installed and in ActivateFeature it activates a feature. This causes any custom code associated with the feature to rerun.

Recommendation : Try to avoid the use of force attribute and only use it when retracting is not able to clean up the features.

5.Use of AllContentUrls attribute:
You may not have used it directly but if you remember the drop down saying deploy on All Web Applications ? , that what it is.

Don't use this.

Recommendation : Deploying the solution to each of the web application. If you have a lot of Web Applications then you can script it.

Tuesday, July 21, 2009

Deployment stuck at deploying message

Scenario:
While trying to deploy a new solution , I was able to add the solution successfully but then deployment got stuck at deploying message.

Solution:
There is no perfect solution to it but there are couple of things you need to try.

Usually this problem is not with your solution but with any specific server in a multi-server farm. So before you open ticket with Microsoft, make sure you see the same behaviour for your solution on another machine.

Check few things:
1. Go to Central Administration
2. Navigate to Operations > "Global Configuration" > "Timer job status".
3. Look for Jobs name starting with either "Windows SharePoint Services Solution Deployment for "

There will be one entry for each of the front-end servers that the solution is being deployed to or retracted from. Usually one of the entries will say failed and the others will say succeeded so you can use this to help figure out which front-end is causing the problems.

Options:
1. If you are trying to deploy the solution globally, try retracting one by one from each web-application

2. If you are trying to deploying the solution using UI try command line STSADM or vise versa.

3. Try running following STSADM command.
STSADM -o execadmsvcjobs ( On all the servers )

4. If it is getting stuck only on a particular Web Application ( more commonly on Central Web Application ), then try deploying it first on another Web Application.

5. Restart the machine and try one more time.

6. Also if it is multi-server farm, try deploying from other machine.

Article:
STADM Commands

Monday, June 22, 2009

Feature testing in different sharepoint environment

Scenario:
Often in sharepoint we need to test a particular functionality with respect to different permission groups ( visitors / members / owners ) for testing.

Solution:
One common approach is to create multiple accounts for each type of access, but that eats up good amount of time switching back and forth.

So I wrote a quick script , which create 1 top level site and 3 more site collections for each type of access group.

Checkout the Urls in the script , you will understand what I meant by that. Idea is that same account will be in different permission group in different site collections. So you can switch permissions based on different urls.

Code:

@SET AdminAccount="training\administrator"
@SET AdminEmail="admin@training.com"
@SET SiteTemplate="STS#0"


Echo ==================================
@SET MAINSITEURL="http://localhost"

Echo Dropping the site collection
stsadm -o deletesite -url %MAINSITEURL%

Echo Recreating fresh site collection
stsadm -o createsite -url %MAINSITEURL% -sitetemplate %SiteTemplate% -ownerlogin %AdminAccount% -owneremail %AdminEmail% -title "Home"

Echo ==================================
@SET MAINSITEURL="http://localhost/sites/visitor"

Echo Dropping the site collection
stsadm -o deletesite -url %MAINSITEURL%

Echo Recreating fresh site collection
stsadm -o createsite -url %MAINSITEURL% -sitetemplate %SiteTemplate% -ownerlogin %AdminAccount% -owneremail %AdminEmail% -title "Visitors"

Echo ==================================
@SET MAINSITEURL="http://localhost/sites/members"

Echo Dropping the site collection
stsadm -o deletesite -url %MAINSITEURL%

Echo Recreating fresh site collection
stsadm -o createsite -url %MAINSITEURL% -sitetemplate %SiteTemplate% -ownerlogin %AdminAccount% -owneremail %AdminEmail% -title "Members"

Echo ==================================
@SET MAINSITEURL="http://localhost/sites/owners"

Echo Dropping the site collection
stsadm -o deletesite -url %MAINSITEURL%

Echo Recreating fresh site collection
stsadm -o createsite -url %MAINSITEURL% -sitetemplate %SiteTemplate% -ownerlogin %AdminAccount% -owneremail %AdminEmail% -title "Owners"

Echo ==================================
pause

Sunday, June 21, 2009

STSADM solution sync issue

Scenario:
We have a big farm and commonly found a problem of solutions not getting sync on all servers, what i meant was we can feature features and other files not getting copied on all the servers and so causing issues.

Solution:
Few things to note before I talk about solution

-- Dont rush while installing solution on multi-server farm because timer jobs runs at different timings and can take some time before you see all the deployed files.So make sure to give your solution atleast 5 minutes before you declare its an issue.

-- If your deployment is stuck then you can run following command to force stuck solution deployment.

STSADM -o execadmsvcjobs
-- Still you see issues with solution files, then you can run
STSADM -o syncSolution -name mysolution.wsp
-- Also I recommend using Solution Installer as this has robust installation mechanism and can rollback in case of some issues.

Article:
STSADM

Follow me on Twitter

Wednesday, June 10, 2009

Post build script for sharepoint based projects

Scenario:
Visual Studio projects doesn't provide any support for the WSP Deployment. And usually a developer need to perform lot of addition steps to make sure deployment is smooth. Here's a script i commonly used

Steps:
Assuming you have a single server farm
1. Make sure you have the correct WSP Builder location
2. Make sure to have a Solution folder created where this script will drop the WSP

Code:


@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template"
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
@SET WSPPBUILDER="C:\Code\WSPBuilder\Buildx86\WSPBuilder.exe"
@SET WSPNAME="MySolution.wsp"
@SET MAINSITEURL="http://localhost"
@SET CENTRALADMINURL="http://localhost:80808"

Echo Creating Solution Package
del Solution\*.* /Q

@echo off
Echo Creating Solution Package
%WSPPBUILDER% -outputpath Solution -wspname %WSPNAME%

Echo Recycling AppPool ( To avoid any file locking issues )
IISRESET

Echo ==== Starting Clean up ===

Echo Deactivating Features
%STSADM% -o deactivatefeature -name MyFeature -url % MAINSITEURL%

Echo Uninstalling Features
%STSADM% -o uninstallfeature -name MyFeature -force

Echo Retracting Solution
%STSADM% -o retractsolution -name %WSPNAME% -immediate
%STSADM% -o execadmsvcjobs

Echo Deleting Solution
%STSADM% -o deletesolution -name %WSPNAME%

Echo Deleting all the deployed files including GAC-ed Assemblied
rmdir %TEMPLATEDIR%\FEATURES\MyFeature /S /Q

Echo ==== Done Clean up ===
Echo
Echo ==== Starting Fresh ===
Echo Adding Solution
%STSADM% -o addsolution -filename Solution\%WSPNAME%

Echo Deploying solution
%STSADM% -o deploysolution -name %WSPNAME% -immediate -allowGacDeployment
%STSADM% -o execadmsvcjobs

Echo Recycling IIS
IISRESET

Echo Activating Feature
%STSADM% -o activatefeature -name MyFeature -url % MAINSITEURL%

Echo ==== Done fresh deployment ===
Note:
This script hold good for sandbox and need changes to script for an other type deployment like Development , Staging and Production.

Friday, May 29, 2009

Checklist for ASP.Net and Sharepoint

Version Control:
-- All the code changes should be checked in
-- Label the build with proper Product Version Number

Refactoring Checklist:

-- Remove the extra namespace references, you can use VS to do this
-- Add some inline comments
-- Make sure you not using System.Data.SqlClient in UI code-behind class, it should only be used in Data Layer
-- Remove the Source Control binding
-- Make sure to Encrypt the connection strings and other sensitive information
-- Remove any hard-coded test accounts
-- Compile the project to RELEASE mode
-- If using any timer job, make the timer interval configurable
-- For any Window Service, make the timer interval configurable
-- Set some standard in-term of maximum lines of code per file ( 100-200 lines ) , and refactor accordingly.
-- Make sure assemblies are strongly named
-- Compile the project for minimum .net framework
-- Use Try Catch Finally blocks to handle exception
-- Use a robust logging framework ( i.e. log4net ) in-spite of redeveloping your own

Database Checklist:
-- Use a naming conversion for all the tables ( Users , Employees )
-- Make sure to create limited SPs per table ( GetAll, Get, Add, Update, Delete or Remove)
-- Only grant ‘execute' permission on all stored procedures, and grant that permission only for the application domain group.
You can use the Database roles with EXEC permissions to Stored Procedure.
-- Do not use "exec @sql" construct in your stored procedures , only use stored procedures.

Deployment Checklist:

-- If you using AppSettings make sure all of them point to proper server (Production server)
-- Prepare script for retracting the solutions and of-course for deploying the solutions
-- Prepare pre-install / post-install scripts for any additional operation which need to executed on each individual server
-- In case you are replacing system files , make sure you back them up and need to be restored when you back-out

Code Quality Checklist:

-- Unit Tests
-- Address Cross Scripting issues
-- Address for SQL Injection issues, use Stored Procedures
-- Address Blind SQL Injection

Wednesday, March 25, 2009

Activating multiple features in one shot

Scenario:
You want to activate multiple features in one shot.

Solution:
I hacked this solution from out-of-box TeamCollab feature. The TeamCollab feature is an interesting feature because it uses a technique known as feature dependency. Feature dependency enables you to package several features in one feature and activate them all by activating the containing feature. Below is the example of the technique.

Code:

< ?xml version=”1.0” encoding=”utf-8”? >
< Feature Id=”NewGUID”
Title=”BundleFeature”
Description=”This is bundle feature”
ImageUrl=”FeatureLogo.gif”
ImageUrlAltText=””
Scope=”Web”
DefaultResourceFile=”core”
xmlsn=”http://schemas.microsoft.com/sharepoint/” >
< ActivationDependencies >

< !-- Feature 1 -- >
< ActivationDependency FeatureId=”Feature1_GUID” / >

< !-- Feature 2 -- >
< ActivationDependency FeatureId=”Feature2_GUID” / >

< /ActivationDependencies >
< /Feature >