3

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.

I first import several Nuget related items: - Profile.ps1 - nuget.psm1 - NuGet.Cmdlets.dll

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)

$dte = [runtime.interopservices.marshal]::GetActiveObject("visualstudio.dte")

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:

$project = $dte.Solution.Projects.Item("MvcApplication1\MvcApplication1.csproj")

I am able to step into init.ps1: \packages\T4Scaffolding.Core.1.0.0\tools\init.ps1 but the code fails when executing:

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

I also tried pointing to my $project name (omitting -SolutionWide) with the same results.:

Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -Project ($project).Name -DoNotOverwriteExistingSetting

I could observe that EnvDTE.dll is loaded into Powershell ISE environment by using:

[System.Threading.Thread]::GetDomain().GetAssemblies()

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).

Thanks, Rad

Stack Overflow: question I used as a starting point

Community
  • 1
  • 1
Rad
  • 933
  • 1
  • 15
  • 32

1 Answers1

0

I got same error message:

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE

but in different scenario. I was using scaffold in VS2015, installed T4Scaffolding.Core. Then I found the solution from this link
By installing Windows Management Framework 4.0 the error is gone and my scaffold works again. Hopes this can help.

Community
  • 1
  • 1