gpt4 book ai didi

debugging - 调试 T4Scaffolding.Core Nuget 包时的 Set-DefaultScaffolder : Cannot get an instance of EnvDTE. DTE - 高级 Powershell 调试

转载 作者:行者123 更新时间:2023-12-02 14:18:04 31 4
gpt4 key购买 nike

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

我首先导入几个Nuget相关的项目:- 简介.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)。

谢谢,拉德

Stack Overflow: question I used as a starting point

最佳答案

我收到同样的错误消息:

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

但在不同的场景中。我在VS2015中使用脚手架,安装了T4Scaffolding.Core。然后我从this link找到了解决方案
通过安装Windows Management Framework 4.0错误消失了,我的脚手架又可以工作了。希望这可以有所帮助。

关于debugging - 调试 T4Scaffolding.Core Nuget 包时的 Set-DefaultScaffolder : Cannot get an instance of EnvDTE. DTE - 高级 Powershell 调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14256318/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com