MvcScaffolding 是否与 VS 2015 兼容?
Is MvcScaffolding compatible with VS 2015?
我最近升级到 VS 2015,现在当我尝试使用我的脚手架之一时出现以下错误:
Scaffold : Cannot get an instance of EnvDTE.DTE
At line:1 char:1
+ Scaffold Entity
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-Scaffolder], InvalidOperationException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.InvokeScaffolderCmdlet
看起来有一个 similar issue early on with VS 2013 但问题已通过更新 2 解决。
我可以做些什么来让 mvcScaffolding 再次工作,或者有什么新方法可以搭建我的代码?
这是我的自定义脚手架之一的示例:
RestApi.ps1
[T4Scaffolding.Scaffolder(Description = "Enter a description of RestApi here")][CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string[]]$EntityNames,
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)][string]$Inherit,
[string]$Project,
[string]$CodeLanguage,
[string[]]$TemplateFolders,
[switch]$Force = $false
)
$outputPath = "ExampleOutput" # The filename extension will be added based on the template's <#@ Output Extension="..." #> directive
$namespace = (Get-Project $Project).Properties.Item("DefaultNamespace").Value
$baseInherit = $Inherit
if($Inherit -eq ""){
$baseInherit = "BaseRestController"
}
foreach($EntityName in $EntityNames){
$split = $EntityName.Split(":")
$EntityName = $split[0]
if($split[1]){
$Inherit = $split[1]
}else{
$Inherit = $baseInherit;
}
$Entities = Get-PluralizedWord $EntityName
$outputPath = "ApiControllers\"+$Entities+"Api.cs" # The filename extension will be added based on the template's <#@ Output Extension="..." #> directive
Add-ProjectItemViaTemplate $outputPath -Template RestApiTemplate `
-Model @{
Namespace = $namespace;
Entity = $EntityName;
Entities = $Entities;
Inherit = $Inherit
} `
-SuccessMessage "Added RESTApi at {0}" `
-TemplateFolders $TemplateFolders -Project $Project -CodeLanguage $CodeLanguage -Force:$Force
}
RestApiTemplate.cs.t4
<#@ Template Language="C#" HostSpecific="True" Inherits="DynamicTransform" #>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using <#= Model.Namespace #>.Models;
using <#= Model.Namespace #>.Models.ViewModels;
namespace <#= Model.Namespace #>.ApiControllers {
[RoutePrefix("api/<#= Model.Entities.ToLower() #>")]
public class <#= Model.Entities #>Controller : <#= Model.Inherit #><<#= Model.Entity #>, <#= Model.Entity #>ViewModel> {
public <#= Model.Entities #>Controller() : base("<#= Model.Entity #>"){
}
// Use StandardActions to override standard behavior
#region StandardActions
// GetById, All, Add, Update, Delete
#endregion
// Use ExtendedActions to add additional behavior to the API
#region ExtendedActions
#endregion
}
}
我在 VS2015 中遇到了同样的错误。我提取了源代码,修复了错误,并上传了具有链接依赖项的新 NuGet 包。 3 个新包是:
首先卸载MvcScaffolding及其依赖,T4Scaffolding,&T4Scaffolding.Core。如果您然后简单地安装 MvcScaffolding 包,其他包将被拉过。希望这可以帮助别人。
干杯。
我最近升级到 VS 2015,现在当我尝试使用我的脚手架之一时出现以下错误:
Scaffold : Cannot get an instance of EnvDTE.DTE
At line:1 char:1
+ Scaffold Entity
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-Scaffolder], InvalidOperationException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.InvokeScaffolderCmdlet
看起来有一个 similar issue early on with VS 2013 但问题已通过更新 2 解决。
我可以做些什么来让 mvcScaffolding 再次工作,或者有什么新方法可以搭建我的代码?
这是我的自定义脚手架之一的示例:
RestApi.ps1
[T4Scaffolding.Scaffolder(Description = "Enter a description of RestApi here")][CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string[]]$EntityNames,
[parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true)][string]$Inherit,
[string]$Project,
[string]$CodeLanguage,
[string[]]$TemplateFolders,
[switch]$Force = $false
)
$outputPath = "ExampleOutput" # The filename extension will be added based on the template's <#@ Output Extension="..." #> directive
$namespace = (Get-Project $Project).Properties.Item("DefaultNamespace").Value
$baseInherit = $Inherit
if($Inherit -eq ""){
$baseInherit = "BaseRestController"
}
foreach($EntityName in $EntityNames){
$split = $EntityName.Split(":")
$EntityName = $split[0]
if($split[1]){
$Inherit = $split[1]
}else{
$Inherit = $baseInherit;
}
$Entities = Get-PluralizedWord $EntityName
$outputPath = "ApiControllers\"+$Entities+"Api.cs" # The filename extension will be added based on the template's <#@ Output Extension="..." #> directive
Add-ProjectItemViaTemplate $outputPath -Template RestApiTemplate `
-Model @{
Namespace = $namespace;
Entity = $EntityName;
Entities = $Entities;
Inherit = $Inherit
} `
-SuccessMessage "Added RESTApi at {0}" `
-TemplateFolders $TemplateFolders -Project $Project -CodeLanguage $CodeLanguage -Force:$Force
}
RestApiTemplate.cs.t4
<#@ Template Language="C#" HostSpecific="True" Inherits="DynamicTransform" #>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using <#= Model.Namespace #>.Models;
using <#= Model.Namespace #>.Models.ViewModels;
namespace <#= Model.Namespace #>.ApiControllers {
[RoutePrefix("api/<#= Model.Entities.ToLower() #>")]
public class <#= Model.Entities #>Controller : <#= Model.Inherit #><<#= Model.Entity #>, <#= Model.Entity #>ViewModel> {
public <#= Model.Entities #>Controller() : base("<#= Model.Entity #>"){
}
// Use StandardActions to override standard behavior
#region StandardActions
// GetById, All, Add, Update, Delete
#endregion
// Use ExtendedActions to add additional behavior to the API
#region ExtendedActions
#endregion
}
}
我在 VS2015 中遇到了同样的错误。我提取了源代码,修复了错误,并上传了具有链接依赖项的新 NuGet 包。 3 个新包是:
首先卸载MvcScaffolding及其依赖,T4Scaffolding,&T4Scaffolding.Core。如果您然后简单地安装 MvcScaffolding 包,其他包将被拉过。希望这可以帮助别人。
干杯。