title: Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE when debugging T4Scaffolding.Core Nuget package - Advanced Powershell debugging
body: <p>I am trying to debug T4Scaffolding.Core Nuget package from outside Visual Studio 2012.
  I am using Powershell ISE with Powershell 3.0 installed and run under CLRVersion 4.0.30319.</p>
  
  <p>I first import several Nuget related items:
  - Profile.ps1
  - nuget.psm1
  - NuGet.Cmdlets.dll</p>
  
  <p>I am also setting the current location to set-location "\ClassLibrary1\"
  and obtained the only DTE instance currently running (I previously opened MySolution in VS 2012 that has a class library and an asp.net MVC 4 application in it)</p>
  
  <pre><code>$dte = [runtime.interopservices.marshal]::GetActiveObject("visualstudio.dte")
  </code></pre>
  
  <p>I skipped importing Get-Project cmdlet from NuGet.Cmdlets.dll binary module, so I can create my own cmdlets: Get-Project
  that gets my MVC project this way:</p>
  
  <pre><code>$project = $dte.Solution.Projects.Item("MvcApplication1\MvcApplication1.csproj")
  </code></pre>
  
  <p>I am able to step into init.ps1: 
    \packages\T4Scaffolding.Core.1.0.0\tools\init.ps1
  but the code fails when executing:</p>
  
  <pre><code>Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -SolutionWide -DoNotOverwriteExistingSetting
  
  
  Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
  At line:1 char:1
  + Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTempl ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
  + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet
  </code></pre>
  
  <p>I also tried pointing to my $project name (omitting -SolutionWide) with the same results.:</p>
  
  <pre><code>Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -Project ($project).Name -DoNotOverwriteExistingSetting
  </code></pre>
  
  <p>I could observe that EnvDTE.dll is loaded into Powershell ISE environment by using:</p>
  
  <pre><code>[System.Threading.Thread]::GetDomain().GetAssemblies()
  </code></pre>
  
  <p>Hopefully someone will be interested in achieving the same goal (stepping line by line through init.ps1 and install.ps1 of a Nuget package outside Visual Studio).</p>
  
  <p>Thanks,
  Rad</p>
  
  <p><a href="https://stackoverflow.com/questions/7031944/how-to-debug-install-ps1-script-of-nuget-package?rq=1">Stack Overflow: question I used as a starting point</a></p>