Archive

Archive for the ‘Deployment’ Category

How to fix “Error: This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application.”

November 17, 2012 Leave a comment

Problem:

When I try to deploy my custom wsp solution to a specific web application, I got the error below:

This solution contains no resources scoped for a Web application and cannot be deployed to a particular Web application.

Analysis:

The error message itself explains why you cannot deploy the solution to a web application. However if you do not like to deploy the solution to all the web applications and only like to deploy your solution to a specific application , you need to change the solution settings Assembly Deployment Target from GlobalAssemblyCache to WebApplication.

From:

TO:

Solution:

After you change the Assembly Deployment Target and run the script again, you will have the solution deployed successfully.
References:

http://blogs.msdn.com/b/jjameson/archive/2007/06/17/issues-deploying-sharepoint-solution-packages.aspx

Advertisements

How to write PowerShell code part 1 (Using external xml configuration file)

May 13, 2012 1 comment

In this post, I will show you how to use external xml file with PowerShell. The advantage for doing so is that you can avoid other people to open up your PowerShell code to make the configuration changes; instead all they need to do is to change the xml file. I will refactor my site creation script as an example; you can download the script here and refactored code here.

1. As you can see below, I hard code all the variables in the script itself.


$url = "http://ybbest"
$WebsiteName = "Ybbest"
$WebsiteDesc = "Ybbest test site"
$Template = "STS#0"
$PrimaryLogin = "contoso\administrator"
$PrimaryDisplay = "administrator"
$PrimaryEmail = "administrator@contoso.com"
$MembersGroup = "$WebsiteName Members"
$ViewersGroup = "$WebsiteName Viewers"

2. Next, I will show you how to manipulate xml file using PowerShell. You can use the get-content to grab the content of the file.

[xml] $xmlconfigurations=get-content .\SiteCollection.xml

3. Then you can set it to variable (the variable has to be typed [xml] after that you can read the content of the xml content, PowerShell also give you nice IntelliSense by press the Tab key.

[xml] $xmlconfigurations=get-content .\SiteCollection.xml
$xmlconfigurations.SiteCollection
$xmlconfigurations.SiteCollection.SiteName

4. After refactoring my code, I can set the variables using the xml file as below.


#Set the parameters
$siteInformation=$xmlinput.SiteCollection
$url = $siteInformation.URL
$siteName = $siteInformation.SiteName
$siteDesc = $siteInformation.SiteDescription
$Template = $siteInformation.SiteTemplate
$PrimaryLogin = $siteInformation.PrimaryLogin
$PrimaryDisplay = $siteInformation.PrimaryDisplayName
$PrimaryEmail = $siteInformation.PrimaryLoginEmail
$MembersGroup = "$WebsiteName Members"
$ViewersGroup = "$WebsiteName Viewers"

How to write PowerShell code part 1
How to write PowerShell code part 2
How to write PowerShell code part 3
How to write PowerShell code part 4

How to find out which process actually locks your dll when SharePoint Solution deployment failed

March 1, 2012 Leave a comment

When your SharePoint Solution package include third party or external dlls , you will often see your solution fail to deploy due to the locking of the dlls. Today I will show you how to find which process locks your dlls using Process Explorer.

1. Here is an example that your solution fails to deploy due to dll being locked.

2. Start the explorer by double click the procexp.exe

3. From the find tab click Find Handle or DLL

4.Type the your dll name and click Search

5. I can see all the processes that use my dlls at the moment, it looks like the iis , visual studio and SharePoint timer services might be the trouble. From my experience , it could be Visual studio.

6. Close visual studio and redeploy my solution, it works like charm. Re-search the dll, you can see Visual studio is not in the results.

How to fix “The database is in single-user mode, and a user is currently connected to it.”

February 21, 2012 Leave a comment

Recently, when I running the buildscript for a SharePoint. I get the following error message:

[exec] Remove-SPSite : Cannot open database “WSS_Content_YBBEST_AAA_2013′ requested by the login. The login failed.

[exec] Login failed for user ‘YBBEST\administrator’.

Then I went to the SQL Management studio, the database is in Single user mode, not sure how it ends up in that state. When I try to delete the database then I got the following errors:

Changes to the state or options of database ‘WSS_Content_YBBEST_AAA_2013’ cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.

Guess, how to fix the issue?

Restart your SQL Server to fix the problem.

You can restart SQL Server by right click the server in your Management studio and choose restart.

Some guidelines on how to use site Backup and restore as deployment method in SharePoint2010

February 2, 2012 1 comment

Recently, I have done a lot of site deployment using site Backup and restore as deployment method in SharePoint2010 instead of packaging everything as WSP. It is great way to deploy a configuration site from Dev to Uat and then to production. However, there are a few things you need to take into consideration when using this approach.You can download  a copy of the deployment script using this approach here.

  1. This method is used for initial deployment, i.e. you cannot use this approach to deploy new features to existing site collection in production.
  2. You have to make sure the dev ,staging and production have the same version of the SharePoint(i.e. the same Service pack , cumulative update and security update)Otherwise , you will have the following exception when restoring the site collection.

    “Restore-SPSite : Your backup is from a different version of Microsoft SharePoint Foundation and cannot be restored to a server running the current version. The backup file should be restored to a server with version ‘x.x.x.x’ or later.”

  3. Once you restore the solution into another environment, you cannot delete that site and restore again. You should always overwrite the existing site collection. Otherwise , you will get the following errors:

    Restore-SPSite : The operation that you are attempting to perform cannot be completed successfully. No content databases in the web application were available to store your site collection. The existing content databases may have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain a copy of this site collection. Create another content database for the Web application and then try the operation again.

    The reason for that is :Microsoft uses the source site collection GUIDs during the installation. If you delete the site collection from the web application, it leaves the GUIDs behind, and if you try to restore same site collection (same GUID) into same web application and content database, it would throw an error. http://support.microsoft.com/kb/926321 – This is applicable to 2007 and 2010 also.Use the -Force option from Restore-SPSite

  4. User accounts. If you create your content in a different farm that uses different users than your production farm, you have the potential of restoring a site that has different users. Once deployed you would have to update the site with the real users who need access.
  5. Domains. If you create content in a different farm that exists in a different domain (common in companies who segregate their development/test/qa/production environments), not only could you have the wrong users as in my first point, but you may not be able to add the real users into the staging site collection before backup (if there is no domain trust)
  6. Using names that indicate the environment. Say you have an intranet site. If you use the title “Intranet – Dev” when developing the site and do a backup and restore, this will transfer over to production.
  7. The best approach to avoid feature dependency issues is to restore the backup and then deploy the WSP.
  8. If the locations within the farm differ, you could have issues. For example, if in your staging environment the site collection is the root in the web application, but in production it’s under a managed path, you may experience broken links or images within sites after the restore because they will be referencing the wrong absolute path.

References:

http://sharepoint.stackexchange.com/questions/23809/whats-the-downside-of-using-backup-and-restore-site-collection-as-deployment-me

http://sharepoint.stackexchange.com/questions/10574/powershell-restore-spsite-error

http://sharepoint.stackexchange.com/questions/24075/restore-spsite-to-the-same-content-database

PowerShell Code Snippets for SharePoint2010 Developers

February 24, 2011 1 comment

#Install Admin Approved InfoPath form 


#Please specify the template path.

$InfopathFormTemplatePath = "C:\ybbest\myForm.xsn"

#Please specify the site collection url.

$SiteCollectionUrl="http:// ybbest /"

#Install InfoPath to the SharePoint Farm

$formTemplate=Install-SPInfoPathFormTemplate -Path $InfopathFormTemplatePath

#Activate InfoPath form to Site Collection

Enable-SPInfoPathFormTemplate -Identity $formTemplate -Site $SiteCollectionUrl

# Add .Net Framework Windows Feature Using PowerShell


Import-Module ServerManager
Add-WindowsFeature NET-Framework
Add or Remove a computer from Domain
Add-Computer -domainname ybbest; Rrestart-Computer
Remove-Computer -credential ybbest\beny -force; Restart-Computer

#Pre-Deployment command script to recreate the site collection

stsadm -o deletesite -url <a href="http://ybbest">http://ybbest</a>
stsadm -o createsite -url <a href="http://ybbest">http://ybbest</a> -owneremail beny@ybbest.com -ownerlogin ybbest\beny -sitetemplate STS#1 -title "ybbest Team"

#Create SharePoint site collection using PowerShell

You can download deployment script here.

#Scripts to deploy solution

You can download deployment script here.

#Scripts to add user to SharePoint Group

You can download script here.

#Scripts to import documents to SharePoint document library

You can download script here.

#Scripts to Create Managed Path

You can download script here.

#Scripts to Create Managed Properties

You can download script here.

#Scripts to Hide certain fields on item new and edit form

You can download script here.

#Scripts to create list and library with custom content types.

You can download script here.

References

http://technet.microsoft.com/en-us/library/ee806878.aspx

http://www.wssdemo.com/Lists/PowerShell/Commands.aspx

http://www.sharepointproconnections.com/article/sharepoint/Create-a-SharePoint-Site-Collection-with-Windows-PowerShell-UI-Style.aspx

http://www.devexpertise.com/2009/02/06/sharepoint-list-template-ids-and-site-template-ids/

Deploying SharePoint 2010 Solution Package Using PowerShell (Revisited)