3
Vote

Creating separate T4Scaffolding.Core package with base functionality

description

I'm building scaffolding packages for building Silverlight, WinRT, Windows Phone business applications and I need base T4Scaffolding package, that have the base classes from T4Scaffolding package and can be installed on Silverlight/WP/WinRT projects.
Current T4Scaffolding conatins some base templates for generating EntityFramework dbcontexts and requires asssemblies referenced in the project where T4Scaffolding is installed.
I have modified T4Scaffolding and created T4Scaffolding.Core package that works with Silverlight and RIA Services client entities. I want to make the project public so anyone can use the package and extend the templates. I can provide list with changes and steps that should be made for creating the core package.

file attachments

comments

SteveSanderson wrote Jan 25, 2012 at 3:05 PM

Hi

Following your suggestion I've spiked up a candidate implementation in the "WithT4Scaffolding.Core" branch.

Could you have a look at this, try it out, and let me know if that would meet your needs? My main focus is elsewhere right now, so I'm not able to dig too deep into it. If by any chance you are able to spend some time testing that the updates work in all the main cases, e.g.:
  • Installing MvcScaffolding from scratch into an MVC 3 project and using it in both C# and VB projects
  • Updating from an older version of MvcScaffolding+T4Scaffolding and using it
  • Installing T4Scaffolding from scratch into an MVC 3 project and using it in both C# and VB projects
  • Updating from an older version of T4Scaffolding and using it
  • Installing T4Scaffolding.Core into a non-web project and using it
... then that would help me justify merging this branch into master and publishing T4Scaffolding.Core to the public feed. No worries if you are unable to do that, but it may be a while before I can do!

Thanks for the suggestion

trustorm wrote Apr 4, 2012 at 6:03 AM

I am trying to use the Core branch but I am getting the following errors when nuget is trying to load T4Scaffolding.dll

PM> Import-Module : Cannot load Windows PowerShell snap-in C:\Users\<user name>\AppData\Local\assembly\dl3\62OG3C6T.
9T5\R6E47PPE.123\5142871e\c70a5967_1b12cd01\T4Scaffolding.dll because of the following error: Unable to load
one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Loader Exceptions:

Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyTo
ken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
At C:\Projects\MyCS\Dev\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:43 char:16
  • Import-Module <<<< $dllPath
    • CategoryInfo : ResourceUnavailable: (:) [Import-Module], PSSnapInException
    • FullyQualifiedErrorId : PSSnapInLoadFailure,Microsoft.PowerShell.Commands.ImportModuleCommand
      The term 'Set-DefaultScaffolder' is not recognized as the name of a cmdlet, function, script file, or operab
      le program. Check the spelling of the name, or if a path was included, verify that the path is correct and t
      ry again.
      At C:\Projects\MyCS\Dev\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:30
  • Set-DefaultScaffolder <<<< -Name CustomTemplate -Scaffolder T4Scaffolding.CustomTemplate -Solutio
    nWide -DoNotOverwriteExistingSetting
    • CategoryInfo : ObjectNotFound: (Set-DefaultScaffolder:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException
The term 'Set-DefaultScaffolder' is not recognized as the name of a cmdlet, function, script file, or operab
le program. Check the spelling of the name, or if a path was included, verify that the path is correct and t
ry again.
At C:\Projects\MyCS\Dev\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:51 char:30
  • Set-DefaultScaffolder <<<< -Name CustomScaffolder -Scaffolder T4Scaffolding.CustomScaffolder -Sol
    utionWide -DoNotOverwriteExistingSetting
    • CategoryInfo : ObjectNotFound: (Set-DefaultScaffolder:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

tbmihailov wrote Apr 4, 2012 at 6:47 PM

Hi, @trustorm

I'm using T4Scaffolding.Core.1.0.0 for a few weeks now and it's working nice in silverlight client application.
Here is the package, I've build for myself with a few modification to work with RIA Services:
https://skydrive.live.com/redir.aspx?cid=bf361213901d682b&resid=BF361213901D682B!1842&parid=BF361213901D682B!1841

Please try that package and check if it works for you. If it does not work make sure you have installed last Nuget manager.

Todor.

trustorm wrote Apr 5, 2012 at 3:31 AM

@tbmihailov Thanks, all fixed

tbmihailov wrote Apr 30, 2012 at 7:13 PM

I've tested T4Scaffolding and MvcScaffolding with T4Scaffolding.Core:
Here are test cases and results:


Date: 21.04.2012 21:00

Performed tests on packages T4Scaffolding and MvcScaffolding with T4Scaffolding.Core.1.0.0.0
  1. Installing MvcScaffolding with T4Scaffolding.Core from scratch into an MVC 3 project and using it in both C# and VB projects
    Steps:
    -Switch to my local test nuget repository with the T4Scaffolding.Core scaffolding version
    Install-Package MvcScaffolding #ok
    Scaffold Controller Category #ok
    Scaffold Controller Products #ok

    -Scaffold CustomController and CustomTemplate were tested and worked!
    PM> Scaffold CustomScaffolder Ninja
    Added scaffolder script 'CodeTemplates\Scaffolders\Ninja\Ninja.ps1'
    Added scaffolder template 'CodeTemplates\Scaffolders\Ninja\NinjaTemplate.cs.t4'
    PM> Scaffold CustomTemplate View Edit
    Added custom template 'CodeTemplates\Scaffolders\MvcScaffolding.RazorView\Edit.cs.t4'
    PM> 
    Above steps were tested in:
    • VS2010 C# MVC3 project - works
    • VS2010 VB MVC3 project - works
    • VS2010 C# MVC4Beta project - works
    • VS2010 VB MVC4Beta project - works

    Updated Nuget in VS11 to 1.7.30402.9028

    • VS11 C# MVC3 project - works
    • VS11 VB MVC3 project - works
    • VS11 C# MVC4Beta project - works
    • VS11 VB MVC4Beta project - works
  2. Updating from an older version of MvcScaffolding+T4Scaffolding to version with T4Scaffolding.Core and using it:
    Steps:
    -Use Official Nuget repository - old version of mvcscaffolding without T4Scaffolding.Core
    Install-Package MvcScaffolding #ok
    Scaffold Controller Category #ok
    Scaffold Controller Products #ok
    -Switch to my local test nuget repository with the T4Scaffolding.Core scaffolding version
    Update-Package MvcScaffolding #ok
    -restart visual studio
    Scaffold Controller Category #ok
    Scaffold Controller Products #ok
    -Scaffold CustomController and CustomTemplate were tested and worked
Above steps (scaffolding) were tested in:
- VS2010 C# MVC3 project - works
- VS2010 VB MVC3 project - works
- VS2010 C# MVC4Beta project - works
- VS2010 VB MVC4Beta project - works

#Updated Nuget in VS11 to 1.7.30402.9028
- VS11 C# MVC3 project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
- VS11 VB MVC3 project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
- VS11 C# MVC4Beta project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
- VS11 VB MVC4Beta project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
  1. Installing T4Scaffolding with T4Scaffolding.Core from scratch into an MVC 3 project and using it in both C# and VB projects
    Steps:

    Switch to local nuget repo with T4Scaffolding.Core

    Install-Package T4Scaffolding
    Scaffold DbContext Category -DbContextType StoreContext
    #Added database context 'Models\StoreContext.cs'
    #Added 'Categories' to database context 'Products_VS2010_MVC3_CS.Models.StoreContext'
    Scaffold DbContext Product -DbContextType StoreContext
    #Added 'Products' to database context 'Products_VS2010_MVC3_CS.Models.StoreContext'
    Scaffold Repository Category -DbContextType StoreContext
    #StoreContext already has a member called 'Categories'. Skipping...
    #Added repository 'Models\CategoryRepository.cs'
    Scaffold Repository Product -DbContextType StoreContext
    #StoreContext already has a member called 'Products'. Skipping...
    #Added repository 'Models\ProductRepository.cs'
    
Above steps (scaffolding) were tested in:
- VS2010 C# MVC3 project - works
- VS2010 VB MVC3 project - works
- VS2010 C# MVC4Beta project - works
- VS2010 VB MVC4Beta project - works

Updated Nuget in VS11 to 1.7.30402.9028

- VS11 C# MVC3 project - works
- VS11 VB MVC3 project - works
- VS11 C# MVC4Beta project - works
- VS11 VB MVC4Beta project - works      
  1. Updating from an older version of T4Scaffolding to T4Scaffolding.Core and using it
    Steps:

    Using official Nuget Repository with old T4Scaffolding

    Install-Package T4Scaffolding
    Scaffold DbContext Category -DbContextType StoreContext
    Scaffold DbContext Product -DbContextType StoreContext
    Scaffold Repository Category -DbContextType StoreContext
    Scaffold Repository Product -DbContextType StoreContext

    Switch to local nuget repo with T4Scaffolding.Core

    Update-Package T4Scaffolding

    restart visual studio

    Scaffold DbContext Category -DbContextType StoreContext
    Scaffold DbContext Product -DbContextType StoreContext
    Scaffold Repository Category -DbContextType StoreContext -Force
    Scaffold Repository Product -DbContextType StoreContext -Force
Above steps were tested in:
- VS2010 C# MVC3 project - works
- VS2010 VB MVC3 project - works
- VS2010 C# MVC4Beta project - works
- VS2010 VB MVC4Beta project - works

#Updated Nuget in VS11 to 1.7.30402.9028
- VS11 C# MVC3 project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
- VS11 VB MVC3 project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
- VS11 C# MVC4Beta project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
- VS11 VB MVC4Beta project - DOES NOT WORK - The term 'Scaffold' is not recognized as the name of a cmdlet
  1. Installing T4Scaffolding.Core into a non-web project and using it
    Steps:

    Switch to local nuget repo with T4Scaffolding.Core

    Install-Package T4Scaffolding.Core
    Scaffold CustomScaffolder Ninja
    Scaffold Ninja
    Above steps were tested in:

    nuget 1.7 in VS2010

    • VS2010 C# Library Project - WORKS

    nuget 1.7 in VS2011

    • VS2011 C# Library Project - WORKS
Summary:
  • Installing fresh MvcScaffolding and T4Scaffolding with T4Scaffolding.Core in VS2010 (nuget 1.6 and 1.7) MVC Project is working
  • Updating projects with old MvcScaffolding and T4Scaffolding to those using T4Scaffolding.Core in VS2010 (nuget 1.6 and 1.7) MVC Project is working
  • Installing fresh MvcScaffolding and T4Scaffolding with T4Scaffolding.Core in VS2011 (nuget 1.7) MVC Project is working
  • Updating projects with old MvcScaffolding and T4Scaffolding to those using T4Scaffolding.Core in VS2011 (nuget 1.7) MVC Project IS NOT WORKING - scaffolding library is not loaded
  • Installing and using T4Scaffolding.Core in VS2010 and VS2011 non MVC projects is working
Test solutions are available here:
https://skydrive.live.com/?cid=bf361213901d682b&resid=BF361213901D682B!1841&id=BF361213901D682B!1841