Fix MissingSetupFile Error of Test-SPContentDatabase in SharePoint Migration

Problem:
Getting “MissingSetupFile” errors when you run the “Test-SPContentDataBase” cmdlet on SharePoint content databases during a migration process.
[MissingSetupFile] File [Features\Feature-folder\feature-artifact] is referenced [1] times in the database [SharePoint_Content_database], but is not installed on the current farm. Please install any feature/solution which contains this file. One or more setup files are referenced in the database [SharePoint_Content_database], but are not installed on the current farm. Please install any feature or solution which contains these files.
fix sharepoint test-spcontentdatabase missingsetupfile error
Root Cause:
In SharePoint migration, The source SharePoint 2010 environment sites contain references to some of the Feature files, and those features are not installed in the target SharePoint 2013 Farm.

Solution:

Well, The resolution is: Install & Deploy all solutions from the source farm to the destination farm. Your organization may have built & deployed several customizations such as 3rd party products (such as bamboo solutions), custom WSP solutions, site definitions, Features, event receivers, Web Parts, user controls, etc., in the SharePoint 2010 environment. You have to install and deploy all these binaries & solutions to your destination SharePoint 2013 environment before testing content databases for an upgrade.

Deploy Solutions from Source Farm to the Destination farm:

  • Go to SharePoint Central Administration >> Navigate to “Solution Management” >> Manage Farm Solutions from System Settings of your SharePoint 2010 Farm (or any SharePoint source farm).
  • Make an inventory of all your WSP Solutions deployed to the farm. Identify the Web Applications to which these solutions are deployed to.
  • Download all WSP files and port it to the target farm. Deploy all of them in the target as per the source farm.

Instead of manually doing the above steps, you can use PowerShell to automate:

  1. How to Extract & Download All WSP Solution Files in SharePoint
  2. How to Install & Deploy Multiple WSP Solutions using PowerShell in SharePoint

What if you don’t need those missing feature artifacts such as web parts in your Target farm and cleanup missing setup files from the content database?

PowerShell script to find & delete missing setup files:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function Run-SQLScript($SQLServer, $SQLDatabase, $SQLQuery)
{
    $ConnectionString = "Server =" + $SQLServer + "; Database =" + $SQLDatabase + "; Integrated Security = True"
    $Connection = new-object system.data.SqlClient.SQLConnection($ConnectionString)
    $Command = new-object system.data.sqlclient.sqlcommand($SQLQuery,$Connection)
    $Connection.Open()
    $Adapter = New-Object System.Data.sqlclient.sqlDataAdapter $Command
    $Dataset = New-Object System.Data.DataSet
    $Adapter.Fill($Dataset) 
    $Connection.Close()
    $Dataset.Tables[0]
}

#Define configuration parameters
$Server="Ab-SQL-001"
$Database="SP10_Content_KM"
$SetupFile="Features\Crescent.Intranet.WebParts\WEFnews\WEFnews.dwp"

#Query SQL Server content Database to get information about the MissingFiles
$Query = "SELECT * from AllDocs where SetupPath like '"+$SetupFile+"'"
$QueryResults = @(Run-SQLScript -SQLServer $Server -SQLDatabase $Database -SQLQuery $Query | select Id, SiteId, WebId)

#Iterate through results
foreach ($Result in $QueryResults)
{
    if($Result.id -ne $Null)
    {
        $Site = Get-SPSite -Limit all | where { $_.Id -eq $Result.SiteId }
        $Web = $Site | Get-SPWeb -Limit all | where { $_.Id -eq $Result.WebId }

        #Get the URL of the file which is referring the feature
        $File = $web.GetFile([Guid]$Result.Id)
        write-host "$($Web.URL)/$($File.Url)" -foregroundcolor green
        
        #$File.delete()
    }
}

This script gets you all locations where the missing setup file is referenced (and optionally delete them!). Don’t forget to set the variables $Server, $Database, and $SetupFile appropriately!

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

3 thoughts on “Fix MissingSetupFile Error of Test-SPContentDatabase in SharePoint Migration

  • You cannot call a method on a null-valued expression.
    At C:\Users\SPSERVICE\Documents\missing files dependencies in shareepoint 2013 after migration.ps1:34 char:9
    + $File = $web.GetFile([Guid]$Result.Id)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    /
    You cannot call a method on a null-valued expression.
    At C:\Users\SPSERVICE\Documents\missing files dependencies in shareepoint 2013 after migration.ps1:37 char:9
    + $File.delete()
    + ~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Reply
  • Hello,
    When I tried to delete the file I got the message below

    Exception calling “Delete” with “0” argument(s): “System.NullReferenceException: Object reference not set to an instance of an object.
    at Microsoft.SharePoint.WorkflowServices.WorkflowDefinitionStorageEventReceiver.ItemDeleting(SPItemEventProperties properties)”
    At line:1 char: 1
    $file.Delete()

    CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    FullyQualifiedErrorId : SPException

    Can you help me to resolve this error?
    Thank you

    Reply
  • $File = $web.GetFile([Guid]$Result.Id) // Error on this line
    At this line i am getting this Error: You cannot call a method on a NULL valued expression
    + categotyInfo InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId: InvikeMethodOnNull

    I can see GUID value of $Result.Id using write-host

    What’s wrong ?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *