Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:01:03+00:00 2026-06-04T07:01:03+00:00

I have written a custom scaffolder for MVC3 using T4 templates to scaffold a

  • 0

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:

Invoke-ScaffoldTemplate : Unable to add ‘UpdateCustomerCoupon.sql’. A
file with that name already exists. At line:1 char:23
+ param($c, $a) return . <<<< $c @a
+ CategoryInfo : NotSpecified: (:) [Invoke-ScaffoldTemplate], COMException
+ FullyQualifiedErrorId : T4Scaffolding.Cmdlets.InvokeScaffoldTemplateCmdlet

It doesn’t matter if the file exists at the output location or not. I get this error every time.

Here is the PowerShell script for the scaffolder:

[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"

And here is the T4 Template code:

<#@ Template Language="C#" HostSpecific="True" Inherits="DynamicTransform" Debug="True" #>
<#@ Output Extension="sql" #>
<#@ assembly name="System.Collections" #>
<#@ assembly name="System.Configuration" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Web" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Configuration" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Web" #>
USE [<#= Model.DatabaseName #>]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Delete<#= Model.TableName #>] (
    @P<#= Model.TableName #>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) = '[<#= Model.TableName #>] ID ''' + CAST(@P<#= Model.TableName #>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
                [<#= Model.TableName #>]
            WHERE
                [ID] = @P<#= Model.TableName #>ID
        COMMIT

        SELECT CAST(1 AS INT)
    END TRY
    BEGIN CATCH
        ROLLBACK
        SELECT CAST(-2 AS INT)
    END CATCH

    RETURN

I invoke the scaffolder by typing “Scaffold DeleteSQL -DatabaseName $DatabaseName -TableName $TableName” into the Package Manager Console.

I have also tried invoking the scaffolder with the -Force option like this: “Scaffold DeleteSQL -DatabaseName $DatabaseName -TableName $TableName -Force“. I have also used “-Force true” and “-Force:true” with no luck. Also notice that the $Force parameter is set to true anyway, so I think it should overwrite by default, right?

What do I need to do to get rid of this error?

Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:01:04+00:00Added an answer on June 4, 2026 at 7:01 am

    Looks like the problem had to do with the path the output was generate to.

    I changed this line in the PowerShell script:

    $outputPath = "Scripts/SQL/$TableName/Delete$TableName"
    

    to this:

    $outputPath = "Scripts\SQL\$TableName\Delete$TableName"
    

    The only thing I changed was the slashes from “/” to “\”. Now, I don’t get the error message anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using nant to build our product and have written a custom task to
Have you written custom balancers for sharding to balance chunks not using the balancer
I am using ASP.NET MVC 2 Preview 2 and have written a custom HtmlHelper
I have written a custom template loader, and templates may change during the lifetime
I'm using Ant 1.8.2 with Java 6. I have written a custom task for
I have written a windows service, which monitors a database table for pending jobs
I have written a custom class to handle database queries to a remote and
I have written a Custom Content Provider on top of a SQLite Database. The
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have written a custom request handler in solr to meet my business requirements.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.