Is MvcScaffolding VS 2015 compliant?

I recently upgraded to VS 2015 and now I get the following error when I try to use one of my forests:

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 problem early on with VS 2013 , but the issue was resolved with Update 2.

Is there something I can do to get mvcScaffolding to work again or is there a new way that I should mimic my code?

Here's an example of one of my custom forests:

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 <#@ 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 <#@ 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
    }
}

      

+3


source to share


1 answer


I faced this same error in VS2015. I pulled out the source, fixed the bugs, and downloaded new NuGet packages with associated dependencies. 3 new packages:



First uninstall MvcScaffolding and its dependencies, T4Scaffolding and T4Scaffolding.Core. If you then simply install the MvcScaffolding package , the other packages will be carried over. Hope this helps someone else.

Greetings.

+1


source







All Articles