Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3/T4 Custom Scaffolder Gives File Exists Error Even When File Doesn't Exist
    primarykey
    data
    text
    <p>I have written a custom scaffolder for MVC3 using T4 templates to scaffold a delete stored procedure for a database and table passed to the scaffolder as parameters. When I run the scaffolder the output file is created in the correct place, but I get the following error:</p> <blockquote> <p>Invoke-ScaffoldTemplate : Unable to add 'UpdateCustomerCoupon.sql'. A file with that name already exists. At line:1 char:23 + param($c, $a) return . &lt;&lt;&lt;&lt; $c @a + CategoryInfo : NotSpecified: (:) [Invoke-ScaffoldTemplate], COMException + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.InvokeScaffoldTemplateCmdlet</p> </blockquote> <p>It doesn't matter if the file exists at the output location or not. I get this error every time.</p> <p>Here is the PowerShell script for the scaffolder:</p> <pre><code>[T4Scaffolding.Scaffolder(Description = "Enter a description of DeleteSQL here")][CmdletBinding()] param( [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string]$DatabaseName, [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string]$TableName, [string]$Project, [string]$CodeLanguage, [string[]]$TemplateFolders, [switch]$Force = $true ) $outputPath = "Scripts/SQL/$TableName/Delete$TableName" Add-ProjectItemViaTemplate $outputPath -Template DeleteSQLTemplate ` -Model @{ TableName = $TableName; DatabaseName = $DatabaseName; Project = $Project } ` -SuccessMessage "Added DeleteSQL output at {0}" ` -TemplateFolders $TemplateFolders -Project $Project -CodeLanguage $CodeLanguage -Force:$Force Write-Host "Scaffolded DeleteSQL" </code></pre> <p>And here is the T4 Template code:</p> <pre><code>&lt;#@ Template Language="C#" HostSpecific="True" Inherits="DynamicTransform" Debug="True" #&gt; &lt;#@ Output Extension="sql" #&gt; &lt;#@ assembly name="System.Collections" #&gt; &lt;#@ assembly name="System.Configuration" #&gt; &lt;#@ assembly name="System.Data" #&gt; &lt;#@ assembly name="System.Web" #&gt; &lt;#@ import namespace="System.Collections.Generic" #&gt; &lt;#@ import namespace="System.Configuration" #&gt; &lt;#@ import namespace="System.Data" #&gt; &lt;#@ import namespace="System.Data.SqlClient" #&gt; &lt;#@ import namespace="System.Web" #&gt; USE [&lt;#= Model.DatabaseName #&gt;] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[Delete&lt;#= Model.TableName #&gt;] ( @P&lt;#= Model.TableName #&gt;ID AS BIGINT, @PChangedByUserID BIGINT, @PChangedByURL VARCHAR(1024), @PChangedByIpAddress varchar(16) ) AS SET NOCOUNT ON BEGIN TRY BEGIN TRANSACTION -- update user history DECLARE @userHistoryID BIGINT = 0; DECLARE @details VARCHAR(4096) = '[&lt;#= Model.TableName #&gt;] ID ''' + CAST(@P&lt;#= Model.TableName #&gt;ID AS VARCHAR) + ''' was deleted.' EXEC InsertUserHistory @PChangedByUserID, @details, @PChangedByURL, @PChangedByIpAddress, @userHistoryID OUTPUT -- Rollback transaction if user history was not created IF(@userHistoryID = 0) BEGIN ROLLBACK SELECT CAST(-1 AS INT) RETURN END DELETE FROM [&lt;#= Model.TableName #&gt;] WHERE [ID] = @P&lt;#= Model.TableName #&gt;ID COMMIT SELECT CAST(1 AS INT) END TRY BEGIN CATCH ROLLBACK SELECT CAST(-2 AS INT) END CATCH RETURN </code></pre> <p>I invoke the scaffolder by typing "<strong>Scaffold DeleteSQL -DatabaseName $DatabaseName -TableName $TableName</strong>" into the Package Manager Console.</p> <p>I have also tried invoking the scaffolder with the -Force option like this: "<strong>Scaffold DeleteSQL -DatabaseName $DatabaseName -TableName $TableName -Force</strong>". I have also used "<strong>-Force true</strong>" and "<strong>-Force:true</strong>" with no luck. Also notice that the $Force parameter is set to true anyway, so I think it should overwrite by default, right?</p> <p>What do I need to do to get rid of this error?</p> <p>Thanks for the help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload