3

我正在尝试从 Visual Studio 2012 外部调试 T4Scaffolding.Core Nuget 包。我正在使用安装了 Powershell 3.0 的 Powershell ISE,并在 CLRVersion 4.0.30319 下运行。

我首先导入几个 Nuget 相关项: - Profile.ps1 - nuget.psm1 - NuGet.Cmdlets.dll

我还将当前位置设置为 set-location "\ClassLibrary1\" 并获得了当前运行的唯一 DTE 实例(我之前在 VS 2012 中打开了 MySolution,其中有一个类库和一个 asp.net MVC 4 应用程序)

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

我跳过了从 NuGet.Cmdlets.dll 二进制模块导入 Get-Project cmdlet,因此我可以创建自己的 cmdlet:Get-Project 以这种方式获取我的 MVC 项目:

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

我可以进入 init.ps1: \packages\T4Scaffolding.Core.1.0.0\tools\init.ps1 但代码在执行时失败:

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

我还尝试指向我的 $project 名称(省略 -SolutionWide),结果相同:

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

我可以观察到 EnvDTE.dll 通过使用以下方法加载到 Powershell ISE 环境中:

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

希望有人会对实现相同的目标感兴趣(逐行通过 Visual Studio 外部 Nuget 包的 init.ps1 和 install.ps1)。

谢谢,拉德

堆栈溢出:我用作起点的问题

4

1 回答 1

0

我得到了同样的错误信息:

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

但在不同的情况下。我在 VS2015 中使用脚手架,安装了 T4Scaffolding.Core。然后我从这个链接
中找到了解决方案, 通过安装Windows Management Framework 4.0,错误消失了,我的脚手架再次工作。希望这能有所帮助。

于 2015-12-19T05:23:14.560 回答