I recently upgraded to VS 2015 and now I get the following error when I try and use one of my scaffolders:
Scaffold : Cannot get an instance of EnvDTE.DTE
At line:1 char:1
+ Scaffold Entity
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-Scaffolder], InvalidOperationException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.InvokeScaffolderCmdlet
It looks like there was a similar issue early on with VS 2013 but that the issue was resolved with Update 2.
Is there something that I can do to get mvcScaffolding working again or is there a new way that I should be scaffolding my code?
Here is an example of one of my custom scaffolders:
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
}
}