3

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
    }
}
Community
  • 1
  • 1
JustMaier
  • 2,101
  • 21
  • 23
  • You got any solution? the latest stable release is older than the 2013 fix. What about 2015 – BiLaL Sep 13 '15 at 08:50
  • https://www.nuget.org/packages/MvcScaffolding/1.0.9/ – BiLaL Sep 13 '15 at 08:50
  • @BiLaL still no luck. I contacted the original devs of MvcScaffolding and they said they had no plans to support VS 2015 or VS 2013 update 4. The source is available [here](https://mvcscaffolding.codeplex.com/), maybe someone could get it to work... – JustMaier Sep 16 '15 at 21:58
  • Thanks for the reply and hope one day someone will be able to carry it forward. – BiLaL Sep 17 '15 at 11:17

1 Answers1

1

I came across this same bug in VS2015. I pulled the source, fixed the bugs, and uploaded new NuGet packages with linked dependencies. The 3 new packages are:

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

Cheers.

  • It works! I reinstalled VS2015 just to try this. I had uninstalled VS2015, because of other issues (Go To Definition bug). It appears that the latest update to VS2013 also causes issues with the existing MvcScaffolding package. Are your changes open source and are you open to sharing what you did so I can look at making it VS2013 Update 5 friendly? – JustMaier Sep 29 '15 at 17:10
  • Certainly. Can you first confirm if the new package also works in VS2013 please? I'm awaiting feedback from the original authors as to whether I can upload the new source on Github. The original source can be found here: https://mvcscaffolding.codeplex.com/SourceControl/latest. I updated a series of dlls with a new reference to allow them to build, but the main fix was in T4Scaffolding.NuGetServices.Services.ScaffoldingSolutionManager constructor. Update assignment to _dte with: _dte= (DTE)Package.GetGlobalService(typeof(DTE)) ?? (DTE)Marshal.GetActiveObject("visualstudio.dte"); Cheers. – David Douglas Anderson Sep 30 '15 at 10:10
  • Hey David, I can confirm that the new package does not work in VS2013 with Update 5. `Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))`. Is there another set of dlls that need to be used for VS2013? – JustMaier Sep 30 '15 at 18:50
  • I see. Thanks for checking. I would need to reinstall VS2013 and rebuild under that I believe. I'll leave it up to you to tackle if you wish: https://github.com/processedbeets/ASP.NET-MVC-Scaffolding This is my version of the original source, so contains the fix for 2015. Cheers. – David Douglas Anderson Oct 01 '15 at 10:57