gpt4 book ai didi

c# - MvcScaffolding 是否与 VS 2015 兼容?

转载 作者:行者123 更新时间:2023-11-30 17:42:44 25 4
gpt4 key购买 nike

我最近升级到 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包,其他包将被拉过。希望这可以帮助别人。

干杯。

关于c# - MvcScaffolding 是否与 VS 2015 兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31689873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com