MvcScaffolding与VS 2015兼容吗?

时间:2015-07-29 01:39:28

标签: c# asp.net-mvc-5 visual-studio-2015 scaffolding asp.net-mvc-scaffolding

我最近升级到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,但问题已通过Update 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
    }
}

1 个答案:

答案 0 :(得分:1)

我在VS2015中遇到了同样的错误。我删除了源代码,修复了错误,并上传了带有链接依赖项的新NuGet包。 3个新包装是:

首先卸载MvcScaffolding及其依赖项,T4Scaffolding,&amp; T4Scaffolding.Core。如果您只是安装MvcScaffolding包,其他包将被拉过来。希望这有助于其他人。

干杯。