title: Azure DevOps custom build task extension cannot find PowerShell VstsTaskSdk.psd1 when target entry file is not in root directory
body: <p>I built the <a href="https://marketplace.visualstudio.com/items?itemName=deadlydog.WaitBuildAndReleaseTask" rel="nofollow noreferrer">Wait</a> Azure DevOps build/release task extension a while ago, and recently it started reporting the following warning when it runs:</p>
  <blockquote>
  <h2>[warning]Task 'Wait' (1.2.3) is using deprecated task execution handler. The task should use the supported task-lib: <a href="https://aka.ms/tasklib" rel="nofollow noreferrer">https://aka.ms/tasklib</a></h2>
  </blockquote>
  <p>So, following that link to the <a href="https://github.com/microsoft/azure-pipelines-task-lib/blob/master/README.md" rel="nofollow noreferrer">Azure Pipelines Task SDK GitHub repo</a> and then drilling into the <a href="https://github.com/microsoft/azure-pipelines-task-lib/blob/master/powershell/Docs/Consuming.md" rel="nofollow noreferrer">Consuming the PowerShell API SDK link</a> it looks like I need to update my extension from the old <code>PowerShell</code> execution handler to the new <code>PowerShell3</code> execution handler in my <code>task.json</code> file, so I made that change and the code now looks like this:</p>
  <pre><code>  &quot;execution&quot;: {
      &quot;PowerShell3&quot;: {
        &quot;target&quot;: &quot;$(currentDirectory)/Code/Wait.ps1&quot;,
        &quot;workingDirectory&quot;: &quot;$(currentDirectory)&quot;
      }
    }
  </code></pre>
  <p>Following the instructions on the page, I've done <code>Save-Module -Name VstsTaskSdk -Path .\</code> to download the SDK module and have committed it to the <code>ps_modules\VstsTaskSdk</code> directory at the root of my extension's task.</p>
  <p>However, after building and running the extension on an MS Hosted agent, it gives the error:</p>
  <blockquote>
  <h2>[error]File not found: 'D:\a_tasks\Wait_f3e9b3d7-a528-5245-91c7-453406bcb038\1.2.17\Code\ps_modules\VstsTaskSdk\VstsTaskSdk.psd1'</h2>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/tjE8J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tjE8J.png" alt="Azure DevOps task output" /></a></p>
  <p>I noticed that it was looking for the <code>ps_modules</code> directory in the <code>Code</code> directory, so I tried placing it there in my git repo, but that still results in the same error.</p>
  <p>I found <a href="https://stackoverflow.com/questions/41292533/tfs-vsts-custom-build-task-execution-cannot-find-vststasksdk-psd1">this very similar StackOverflow question</a>, but the solution for them was to remove the version directory from their hierarchy of <code>ps_modules\[version]\VstsTaskSdk</code>, which I already don't have.</p>
  <p>I also found <a href="https://www.andrewhoefling.com/Blog/Post/dev-ops-vsts-custom-build-task-extension" rel="nofollow noreferrer">this blog post walking through the process</a>, and it looks like I've done everything correct, but I still get the error.</p>
  <p>This is what my file hierarchy looks like:</p>
  <pre><code>|-- Wait\ &lt;task root&gt;
    |-- Code\
      |-- Convert-Unit.Tests.ps1
      |-- Convert-Unit.psm1
      |-- Wait.ps1
    |-- ps_modules\
      |-- VstsTaskSdk\
        |-- [All the module files, including VstsTaskSdk.psd1]
    |-- icon.png
    |-- task.json
  </code></pre>
  <p>I was thinking the problem might be that I keep my tasks &quot;business logic code&quot; separated from the
  &quot;task infrastructure code&quot;, by placing it in a <code>Code</code> directory; that is, my <code>task.json</code> file and the <code>Wait.ps1</code> target entry point file are not in the same directory. Following this assumption I removed the <code>Code</code> directory and dumped all of the files in the root directory, and the error went away (I'm now getting different errors, but it looks to have solved this one).</p>
  <p>Any thoughts on what I can do to still have my &quot;business logic code&quot; separated from the &quot;task infrastructure code&quot; when migrating over to the new PowerShell execution handler? I'm not sure how it determines where it should look for the <code>ps_modules</code> directory.</p>
  <p>The code is all open source as well, so feel free to <a href="https://github.com/deadlydog/AzureDevOps.Wait" rel="nofollow noreferrer">look at the repo</a>.</p>
  <h2>Update</h2>
  <p>While I was not able to solve the problem of how to have the <code>task.json</code> and target entry point PowerShell script files in separate directories, I was able to make changes so that all of the extension infrastructure code is in the root directory, and the &quot;business logic&quot; code in the <code>Code</code> directory.</p>
  <p>As you can see <a href="https://github.com/deadlydog/AzureDevOps.Wait/tree/master/src/Tasks/Wait" rel="nofollow noreferrer">in the repo</a>, I opted to create a <code>task.ps1</code> file in the tasks root directory, and to use that as the target entry point for the task. Updating to the <code>PowerShell3</code> execution handler also meant having to update how we retrieve the task inputs, so I'm using the <code>task.ps1</code> file to get the inputs and then simply call the <code>Code\Wait.ps1</code> script. This allows me to keep my code nice and isolated, so if Azure DevOps decides to change things up with a new execution handler again, I won't need to touch any of the code in the <code>Code</code> directory, just the <code>task.ps1</code> file.</p>