title: SQL Server database project: Error MSB4018 "SqlDeployTask"
body: <p>To start I have already referenced the following posts</p>
  
  <p><a href="https://stackoverflow.com/questions/7649622/vs2010-database-project-deploy-sqldeploytask-task-failed-unexpectedly-nullr">VS2010 Database project deploy - &quot;SqlDeployTask&quot; task failed unexpectedly, NullReferenceException</a></p>
  
  <p><a href="http://social.msdn.microsoft.com/Forums/en/vstsdb/thread/e848f09f-5d5d-46d5-b27a-c7769b188c78" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en/vstsdb/thread/e848f09f-5d5d-46d5-b27a-c7769b188c78</a></p>
  
  <p>I have a Database project which is connected to Team Foundation Server. I have been successfully creating/modifying tables and procedures and deploying to the database. At one point I think there was a sync issue between my local project and TFS <em>(I probably forgot to check in changes before checking out)</em> Since this happened I have been unable to deploy the project. I receive the following error:</p>
  
  <pre><code>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): Error MSB4018: The "SqlDeployTask" task failed unexpectedly.
  System.NullReferenceException: Object reference not set to an instance of an object.
     at Microsoft.Data.Schema.Sql.SchemaModel.SqlScriptDomGenerator.AlterStatementGenerator.GenerateStatement(IModelElement modelElement)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.AlterStatementGeneratorBase.GenerateAlterProcedureStatement(IModelElement oldElement, IModelElement newElement)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.AlterStatementGeneratorBase.GenerateStatement(IModelElement oldElement, IModelElement newElement)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.AlterStatementGeneratorBase.GenerateScriptDom(IModelElement oldElement, IModelElement newElement)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.DeploymentScriptDomGenerator.GenerateFragment(Int32 operation, IModelElement element)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.DeploymentScriptDomGenerator.GenerateSteps(Int32 operation, IModelElement element)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.OrderedStepGenerator.Add(DeploymentScriptDomGenerator scriptDom, IModelElement element, Int32 operation)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.PlanMediator.BuildDependencyOrderedSteps(Int32 operation, List`1 classOrder, List`1 operationOrder, Dictionary`2 changes, Boolean preserveGraphs, Dictionary`2&amp; relating, Dictionary`2&amp; related)
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.PlanMediator.BuildOperations()
     at Microsoft.Data.Schema.Sql.Build.SqlDeploymentPlanGenerator.OnGeneratePlan()
     at Microsoft.Data.Schema.Build.DeploymentPlanGenerator.GeneratePlan()
     at Microsoft.Data.Schema.Build.SchemaDeployment.BuildPlan()
     at Microsoft.Data.Schema.Build.SchemaDeployment.Execute(Boolean executeDeployment)
     at Microsoft.Data.Schema.Build.SchemaDeployment.Execute()
     at Microsoft.Data.Schema.Tasks.DBDeployTask.Execute()
     at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
     at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean&amp; taskResult)
     Done executing task "SqlDeployTask" -- FAILED.
    Done building target "DspDeploy" in project "Ched 10.dbproj" -- FAILED.
   Done executing task "CallTarget" -- FAILED.
  Done building target "DBDeploy" in project "Ched 10.dbproj" -- FAILED.
  Done building project "Ched 10.dbproj" -- FAILED.
  </code></pre>
  
  <p>In the SO post above it looks like the issue was an issue with a function. I have only one function that I have created on my project and have tried removing it from the DB and re-deploying the project with failure. I continued troubleshooting, trying all of the following steps that were listed on the MSDN post above:</p>
  
  <pre><code>1. Unloaded the project, deleted the *.dbmdl files, and reloaded project.
  2. Switch project properties to just create a deploy script
  3. Switch back to creating a deploy script and deploy
  4. Cleaned the project
  </code></pre>
  
  <p>None of these have worked, I am still getting the failure when I set the project to only create a deployment script and not actually deploy.</p>
  
  <p>I have done schema comparisons and have mirrored the data on the DB to the data in my project. Looking at the solution on the MSDN article, the user ended up finding an error in the refactor log. I have looked through the refactor log and see where there could be an issue, however I cannot find how to resolve it. The refactor log has entries that do not exist in either the DB or the project <em>(these were tables or procedures that have been completely removed from the project)</em> </p>
  
  <p>Any ideas on how I could resolve this?</p>
  
  <hr>
  
  <p>Not sure if this helps or not, but here is my refactor log:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Operations Version="1.0"&gt;
    &lt;Operation Name="Rename Refactor" Key="b38ad5f3-ed84-4796-aaa6-4021ae32238e" ChangeDateTime="01/31/2012 19:11:11"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[GetModule]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Procedure" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[GetModuleOutline]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="7e984a2d-8251-4a78-9926-c11e9d3771a3" ChangeDateTime="01/31/2012 20:58:24"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[GetModuleOutline]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Procedure" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[GetModuleOutlineByID]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="62d05d8a-1c45-4b32-94b2-2f0640e48c55" ChangeDateTime="01/31/2012 20:58:35"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[GetSectionOutline]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Procedure" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[GetSectionOutlineByID]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="26fd6cbf-9a72-431b-8399-de3780150f1e" ChangeDateTime="02/01/2012 21:14:35"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[Tracker]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Table" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[StudentSlideProgress]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="c1286fdd-08a7-43a0-b9ac-5137b08bc783" ChangeDateTime="02/01/2012 22:52:45"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[TrackerActionType]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Table" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[SlideActionType]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="3d1fbdbb-9290-4400-9fba-04924f1ac5fd" ChangeDateTime="03/05/2012 22:37:51"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[GetStudentAuthentication]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Procedure" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[GetStudentVerification]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="5d40b8e2-6466-4050-90be-d28d16ac2d86" ChangeDateTime="03/13/2012 18:38:58"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[SetStudentBegin]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Procedure" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[SetStudentSlideBegin]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="5f2d4bd5-95d9-4b8f-91c5-46e89673c93b" ChangeDateTime="03/13/2012 19:01:55"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[SetStudentSlideBegin]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Procedure" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[SetStudentSlideStart]" /&gt;
    &lt;/Operation&gt;
    &lt;Operation Name="Rename Refactor" Key="f4b2ad86-46af-41e8-9d66-4f61bf78e481" ChangeDateTime="03/13/2012 19:14:27"&gt;
      &lt;Property Name="ElementName" Value="[dbo].[SetStudentSlideEnd]" /&gt;
      &lt;Property Name="ElementType" Value="ISql100Procedure" /&gt;
      &lt;Property Name="ParentElementName" Value="[dbo]" /&gt;
      &lt;Property Name="ParentElementType" Value="ISql90Schema" /&gt;
      &lt;Property Name="NewName" Value="[SetStudentSlideStop]" /&gt;
    &lt;/Operation&gt;
  &lt;/Operations&gt;
  </code></pre>