Debugging install-package T4Scaffolding.Core powershell command from outside VS Nuget console

Jan 15, 2013 at 11:21 AM
Edited Jan 15, 2013 at 11:23 AM
I am trying to debug <my .sln folder>\packages\T4Scaffolding.Core.1.0.1\tools\init.ps1 using PowerGUI script editor.
I can successfully attach a VS 2012 debugger to PowerGUI executable.
I am using .net reflector to decompile:
-T4Scaffolding and
-T4Scaffolding.NuGetServices dlls.

Everything is executing fine within init.ps1 until it reaches line:
Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -SolutionWide -DoNotOverwriteExistingSetting

and the PowerGUI console reports:
Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE

The same thing happens when I try to issue:
Get-Scaffolder : Cannot get an instance of EnvDTE.DTE

I found the problem to be on the line:
            this._dte = (DTE) Package.GetGlobalService(typeof(DTE));
inside T4Scaffolding.NuGetServices.dll's ScaffoldingSolutionManager constructor. Basically Package.GetGlobalService method won't return me an instance of DTE.

When I attach to Nuget console and try to install package
install-package T4Scaffolding.Core
I can also step into ScaffoldingSolutionManager constructor, but this time
DTE is properly returned.

So how can I enable line: this._dte = (DTEPackage.GetGlobalService(typeof(DTE));
to work when invoking scripts outside of VS Nuget console manager.

(I can actuall obtain DTE via: $dte = [runtime.interopservices.marshal]::GetActiveObject("visualstudio.dte") command for PowerGUI console
and of course I have only one VS instance open). I can provide my test scripts.
My goal is to debug complex Nuget package installation with 10-50 packages with very deep dependency tree.


        public ScaffoldingSolutionManager(string defaultProjectName)        {

            this._defaultProjectName = defaultProjectName;
Problem>>>  this._dte = (DTE) Package.GetGlobalService(typeof(DTE));

            if (this._dte == null)
                throw new System.InvalidOperationException("Cannot get an instance of EnvDTE.DTE");