Coder Social home page Coder Social logo

bennor / autot4mvc Goto Github PK

View Code? Open in Web Editor NEW
24.0 7.0 9.0 3.28 MB

A zero-configuration Visual Studio 2012+ extension for automatically running T4MVC templates on build and when files are modified in paths that T4MVC cares about.

Home Page: http://bennor.github.io/AutoT4MVC/

License: MIT License

C# 100.00%

autot4mvc's Introduction

What's this for?

There used to be a really sweet macro for Visual Studio that would automatically run T4MVC templates on build. Unfortunately, macro support has been removed from Visual Studio 2012+, so this is an extension that will do the same thing (and more).

T4MVC templates are run under the following conditions (all string comparisons are case-insensitive):

  • a project or solution containing the template is built
  • a file in a "Controllers" folder is saved (in the same project)
  • the settings file "T4MVC.tt.settings.xml" (or "T4MVC.tt.settings.t4") is saved (in the same project)
  • a file is added/removed/renamed in a folder named "Assets", "Content", "Controllers", "CSS", "Images", "JS", "Scripts", "Styles" or "Views" (in the same project)

Note: Drag/drop in the Solution Explorer will not trigger the templates to re-run, as the added/removed events are not fired.

Chirpy and AutoTT do similar things, but Chirpy is overkill if all you want is your T4MVC templates built and I think AutoTT requires configuration.

Just build and install the template using the VSIX file, grab it from the Visual Studio gallery or do it the easy way and use the 'Extension & Updates' manager in Visual Studio 2012, 2013, 2015 or 2017.

autot4mvc's People

Contributors

bennor avatar garysharp avatar rjregenold avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

autot4mvc's Issues

Tidy up documentation

  • Flesh out and update content in gh-pages site.
    • Make sure it's all up to date
    • Show release log (see if there's a way to pull in the info from the release log and style it, but failing that just add a link)
  • Update and align project readme and VS gallery description.

AsyncPackage for VS2015 and later

VS 2019 RC is showing this warning now:
image

The guidance is to move to the new AsyncPackage which was introduced in VS2015. This will make AutoT4MVC incompatible with VS2013 and earlier though.

I will happily create a PR for AsyncPackage - or do we want to maintain support for VS2013? Or do we want two versions to support both?

Parse settings from T4MVC.tt.settings.xml to determine which folders to monitor for changes.

Rather than checking a file's path against a list of common static file folder names, it would be great if AutoT4MVC simply read the settings out of the configuration file that T4MVC already uses. That way it should work no matter how someone has chosen to structure their project.

For this to happen, it needs to parse out the relevant settings at the time when the extension is loaded (and any time the settings file is updated) and use this information to create a customised list of folders to watch which will differ per project.

Regenerate files on save only, not on build?

We have a rather large project and I was initially using this tool and it works well, except for the fact that generating the files on every build has two problems for me:

  1. It always opens up the T4MVC.cs file in our Perforce depot, since the file gets saved, even though there are no changes to the file

  2. It adds a reasonable amount of time to the build process with large projects, which is something I would prefer to avoid.

What I really would like is the ability to have AutoT4MVC monitor file saves and if it matches any of the files that should re-generate the template, that it would then go ahead and do it only at that time, not on build. If files somehow get missed, I can always run it manually :)

I looked at AutoTT, but it is not supported in VS2012 yet, and I am not sure how to start porting it.

hard coded template name

it works only for template "T4MVC.tt"

from your code:
var t4MvcTemplates = FindProjectItems("T4MVC.tt", projects).ToList();

Doesn't seem to be working for me

Hi, I downloaded your extension, but it isn't recompiling my template files. Just to be sure I put in some text that would cause a syntax error in my generated files, but the code compiled just fine and inspecting the generated files show they haven't been regen'd with the breaking change. Any ideas or how to debug?

Uninstall and Install JQuery.UI.Combined package is so slow in a project with AutoT4MVC

This may be a AutoT4MVC bug, or nuget bug, either way it would be great to get it fixed.

This is NuGet 2.5, VS 2012 Update 3 2013, and AutoT4MVC 1.0

Basically It seems like the policy of running on item added/removed/saved is having some unwanted consequences when the project file is having many items added/removed at once by nuget.

When I do Uninstall-Package of JQuery.UI.Combined, see that it takes a looong, long time, attach debugger and break at random I see a call stack with:

0oycex32.dll!Microsoft.VisualStudio.TextTemplating329C81B56F087DB273CD59F2421B901568B702993BDC31B037A56807D0421372135B7B8DAF7AD34EFE6AD1E2B96C8965704B2D440D84325EF4120CCDF84DDF23.GeneratedTextTransformation.TransformText() Line 37 + 0x12 bytes C#
Microsoft.VisualStudio.TextTemplating.11.0.dll!Microsoft.VisualStudio.TextTemplating.TransformationRunner.PerformTransformation() + 0xb53 bytes

Microsoft.VisualStudio.TextTemplating.11.0.dll!Microsoft.VisualStudio.TextTemplating.Engine.ProcessTemplateImplementation(Microsoft.VisualStudio.TextTemplating.TemplateProcessingSession session, string content, Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost host, string className, string classNamespace) + 0xb3 bytes
Microsoft.VisualStudio.TextTemplating.11.0.dll!Microsoft.VisualStudio.TextTemplating.Engine.ProcessTemplate(string content, Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost host) + 0x5c bytes
Microsoft.VisualStudio.TextTemplating.VSHost.11.0.dll!Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ProcessTemplate(string templateInputFile, string templateContent, Microsoft.VisualStudio.TextTemplating.VSHost.ITextTemplatingCallback processingCallback, object hierarchy) + 0x62 bytes
Microsoft.VisualStudio.TextTemplating.VSHost.11.0.dll!Microsoft.VisualStudio.TextTemplating.VSHost.BaseTemplatedCodeGenerator.ProcessTemplate(string inputFileName, string inputFileContent, Microsoft.VisualStudio.TextTemplating.VSHost.ITextTemplating processor, Microsoft.VisualStudio.Shell.Interop.IVsHierarchy hierarchy) + 0x15 bytes
Microsoft.VisualStudio.TextTemplating.VSHost.11.0.dll!Microsoft.VisualStudio.TextTemplating.VSHost.BaseTemplatedCodeGenerator.GenerateCode(string inputFileName, string inputFileContent) + 0x140 bytes
Microsoft.VisualStudio.TextTemplating.VSHost.11.0.dll!Microsoft.VisualStudio.TextTemplating.VSHost.BaseCodeGenerator.Generate(string inputFilePath, string inputFileContents, string defaultNamespace, out System.IntPtr outputFileContents, out int output, Microsoft.VisualStudio.Shell.Interop.IVsGeneratorProgress generateProgress) + 0x62 bytes
Microsoft.VisualStudio.TextTemplating.VSHost.11.0.dll!Microsoft.VisualStudio.TextTemplating.VSHost.BaseCodeGenerator.Microsoft.VisualStudio.Shell.Interop.IVsSingleFileGenerator.Generate(string wszInputFilePath, string bstrInputFileContents, string wszDefaultNamespace, System.IntPtr[] rgbOutputFileContents, out uint pcbOutput, Microsoft.VisualStudio.Shell.Interop.IVsGeneratorProgress pGenerateProgress) + 0x36 bytes

Microsoft.VisualStudio.Web.Application.dll!Microsoft.VisualStudio.Web.Application.WAProject.Microsoft.VisualStudio.Shell.Interop.IVsPersistHierarchyItem.SaveItem(Microsoft.VisualStudio.Shell.Interop.VSSAVEFLAGS saveFlags, string document, uint itemid, System.IntPtr docData, out int isCanceled) + 0x1b8 bytes    

AutoT4MVC.dll!AutoT4MVC.AutoT4MVCPackage.RunTemplates(EnvDTE.Project[] projects) + 0xde bytes   
AutoT4MVC.dll!AutoT4MVC.AutoT4MVCPackage.ItemRemoved(EnvDTE.ProjectItem ProjectItem) + 0x4a bytes   
EnvDTE.dll!EnvDTE._dispProjectItemsEvents_SinkHelper.ItemRemoved(EnvDTE.ProjectItem A_1) + 0xf bytes    

Area? We don't need no stinkin' Areas?

After installing AutoT4MVC I notice T4MVC appends "?Areas=" to all my lovely routes when I don't even use Areas. It seems unlikely, but could AutoT4MVC have something to do with this? I tried commenting out the Areas node in T4MVC.tt.settings.xml and something automagically changed it back as soon as I hit CTRL+S. Could it be AutoT4MVC?

auto

Install Error : Microsoft.VisualStudio.ExtensionManager.MissingTargetFrameworkException

We recently updated to .NET 4.6 (though as far as I know, we still have 4.5 installed). One of our computers (but not the rest?) is having difficulty installing the plugin, with the following error:

3/14/2016 9:58:00 AM - Beginning to install extension to Microsoft Visual Studio Premium 2012 ...
3/14/2016 9:58:00 AM - Install Error : Microsoft.VisualStudio.ExtensionManager.MissingTargetFrameworkException: The extension 'AutoT4MVC' requires a version of the .NET Framework that is not installed.
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForValidDotNetFramework(IExtension extension)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForInstallBlockers(InstallableExtensionImpl extension, IInstalledExtensionList modifiedInstalledExtensionsList, Boolean isNestedExtension, Boolean& olderVersionInstalled)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallInternal(InstallableExtensionImpl extension, Boolean perMachine, Boolean isNestedExtension, IDictionary2 extensionsInstalledSoFar, List1 extensionsUninstalledSoFar, IInstalledExtensionList modifiedInstalledExtensionsList, AsyncOperation asyncOp, UInt64 totalBytesToWrite, UInt64& totalBytesWritten)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.BeginInstall(IInstallableExtension installableExtension, Boolean perMachine, AsyncOperation asyncOp)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallWorker(IInstallableExtension extension, Boolean perMachine, AsyncOperation asyncOp)

3/14/2016 9:58:00 AM - Beginning to install extension to Microsoft Visual Studio Premium 2013...
3/14/2016 9:58:00 AM - Install Error : Microsoft.VisualStudio.ExtensionManager.MissingTargetFrameworkException: The extension 'AutoT4MVC' requires a version of the .NET Framework that is not installed.
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForValidDotNetFramework(IExtension extension)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForInstallBlockers(InstallableExtensionImpl extension, IInstalledExtensionList modifiedInstalledExtensionsList, Boolean isNestedExtension, Boolean& olderVersionInstalled)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallInternal(InstallableExtensionImpl extension, Boolean perMachine, Boolean isNestedExtension, IDictionary2 extensionsInstalledSoFar, List1 extensionsUninstalledSoFar, IInstalledExtensionList modifiedInstalledExtensionsList, AsyncOperation asyncOp, UInt64 totalBytesToWrite, UInt64& totalBytesWritten)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.BeginInstall(IInstallableExtension installableExtension, Boolean perMachine, AsyncOperation asyncOp)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallWorker(IInstallableExtension extension, Boolean perMachine, AsyncOperation asyncOp)

Fails when project created in VS2013 opened in VS2015

I've got T4MVC 1.5.2 working fine under VS2013 Update5. When open the same project in VS2015 the template build fails with:

System.Exception was unhandled by user code
HResult=-2146233088
Message=Template runtime error
Source=acomtdlz
StackTrace:
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.TransformText() in d:\Projects\MyProject\T4MVC.tt:line 423
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at Microsoft.VisualStudio.TextTemplating.TransformationRunner.PerformTransformation()
InnerException:
ErrorCode=-2147467259
HResult=-2147467259
Message=Error HRESULT E_FAIL has been returned from a call to a COM component.
Source=mscorlib
StackTrace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.ExternalElements.ExternalCodeFunction.get_FunctionKind()
at EnvDTE80.CodeFunction2.get_FunctionKind()
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ResultTypeInfo.<.ctor>b__65(CodeFunction2 f) in d:\Projects\MyProject\T4MVC.tt:line 1893
at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.OrderedEnumerable1.d__1.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ResultTypeInfo..ctor(CodeTypeRef codeType) in d:\Projects\MyProject\T4MVC.tt:line 1892
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ProcessControllerActionMethods(ControllerInfo controllerInfo, CodeClass2 current) in d:\Projects\MyProject\T4MVC.tt:line 881
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ProcessControllerType(CodeClass2 type, AreaInfo area, DateTime controllerLastWriteTime) in d:\Projects\MyProject\T4MVC.tt:line 759
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ProcessControllersRecursive(ProjectItem projectItem, AreaInfo area) in d:\Projects\MyProject\T4MVC.tt:line 691
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ProcessControllersRecursive(ProjectItem projectItem, AreaInfo area) in d:\Projects\MyProject\T4MVC.tt:line 676
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ProcessAreaControllers(ProjectItems areaFolderItems, AreaInfo area, ProjectItem areaFolder) in d:\Projects\MyProject\T4MVC.tt:line 646
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.ProcessProjectRoot(Project project) in d:\Projects\MyProject\T4MVC.tt:line 569
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.PrepareDataToRender(TextTransformation tt) in d:\Projects\MyProject\T4MVC.tt:line 545
at Microsoft.VisualStudio.TextTemplating8E8910B59E682CB5902E2DC58F73F722279256FD52EE5A921B3A8A64F8534B2369443515B9A41B29A3B9E1BF4FF88AB1A03EF0EA83A8EB7204C181097889082D.GeneratedTextTransformation.TransformText() in d:\Projects\MyProject\T4MVC.tt:line 40
InnerException:

Clean up project

Now that the extension has grown a little, it's no longer a great idea to have all of the code in a single file, so it needs to be split up into sensible blocks.

Do not check-out TT file under TFS(Source Safe) source control

There can be request (as i have) to not checkout *.tt file which is in my case associated under TFS source control.

To avoid this you must change code in file AutoT4MVCPackage.cs, method RunTemplates , replace current code:

if (!t4MvcTemplate.IsOpen)
   t4MvcTemplate.Open();
t4MvcTemplate.Save();

with this ones:

var projectItem = t4MvcTemplate.Object as VSProjectItem;
if (projectItem != null)
{
    projectItem.RunCustomTool();
}
else
{
    if (!t4MvcTemplate.IsOpen)
        t4MvcTemplate.Open();
    t4MvcTemplate.Save();
}

Here is important change RunCustomTool which execute T4 template without checkout file if file is under TFS.

Monitor "styles" folder as well

This tool monitors "Content", but I use "Styles" folder instead. I assume a very large number of other people do the same, as it's in line with general conventions.

Please add monitors for these:
scripts
styles
js
css
images
assets

There are configurable tools, but they're too "heavy".

MissingTargetFrameworkException

I got exception when install AutoT4MVC on Windows 10.

02.05.2015 09:17:47 - Microsoft VSIX Installer
02.05.2015 09:17:47 - -------------------------------------------
02.05.2015 09:17:47 - Initializing Install...
02.05.2015 09:17:48 - Extension Details...
02.05.2015 09:17:48 - Identifier : c676817c-46cc-47d3-b03c-8a05f499d4a5
02.05.2015 09:17:48 - Name : AutoT4MVC
02.05.2015 09:17:48 - Author : Bennor McCarthy
02.05.2015 09:17:48 - Version : 1.5.2
02.05.2015 09:17:48 - Description : An extension for Visual Studio which automatically runs your T4MVC templates at build time and when you create/remove/rename/save a file that T4MVC cares about.
02.05.2015 09:17:48 - Locale : en-US
02.05.2015 09:17:48 - MoreInfoURL : http://bennor.github.io/AutoT4MVC/
02.05.2015 09:17:48 - InstalledByMSI : False
02.05.2015 09:17:48 - SupportedFrameworkVersionRange : [4.5]
02.05.2015 09:17:48 -
02.05.2015 09:17:48 - Supported Products :
02.05.2015 09:17:48 - Microsoft.VisualStudio.Pro
02.05.2015 09:17:48 - Version : [11.0,14.0]
02.05.2015 09:17:48 - Microsoft.VisualStudio.Premium
02.05.2015 09:17:48 - Version : [11.0,14.0]
02.05.2015 09:17:48 - Microsoft.VisualStudio.Ultimate
02.05.2015 09:17:48 - Version : [11.0,14.0]
02.05.2015 09:17:48 -
02.05.2015 09:17:48 - References :
02.05.2015 09:17:48 -
02.05.2015 09:17:48 - Searching for applicable products...
02.05.2015 09:17:48 - Found installed product - Microsoft Visual Studio 2010 Shell - Integrated Mode
02.05.2015 09:17:48 - Found installed product - Microsoft Visual Studio Premium 2013
02.05.2015 09:17:49 - The extension with ID 'c676817c-46cc-47d3-b03c-8a05f499d4a5' is not installed to Microsoft Visual Studio Premium 2013.
02.05.2015 09:17:49 - Found installed product - Microsoft Visual Studio Professional 2013
02.05.2015 09:17:49 - Found installed product - Microsoft Visual Studio 2013 Shell (Integrated)
02.05.2015 09:17:49 - Found installed product - Global Location
02.05.2015 09:17:49 - Found installed product - ssms
02.05.2015 09:17:50 - The following target products have been selected...
02.05.2015 09:17:50 - Microsoft Visual Studio Premium 2013
02.05.2015 09:17:50 -
02.05.2015 09:17:51 - Beginning to install extension to Microsoft Visual Studio Premium 2013...
02.05.2015 09:17:51 - Install Error : Microsoft.VisualStudio.ExtensionManager.MissingTargetFrameworkException: The extension 'AutoT4MVC' requires a version of the .NET Framework that is not installed.
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForValidDotNetFramework(IExtension extension)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.CheckForInstallBlockers(InstallableExtensionImpl extension, IInstalledExtensionList modifiedInstalledExtensionsList, Boolean isNestedExtension, Boolean& olderVersionInstalled)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallInternal(InstallableExtensionImpl extension, Boolean perMachine, Boolean isNestedExtension, IDictionary2 extensionsInstalledSoFar, List1 extensionsUninstalledSoFar, IInstalledExtensionList modifiedInstalledExtensionsList, AsyncOperation asyncOp, UInt64 totalBytesToWrite, UInt64& totalBytesWritten)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.BeginInstall(IInstallableExtension installableExtension, Boolean perMachine, AsyncOperation asyncOp)
at Microsoft.VisualStudio.ExtensionManager.ExtensionManagerService.InstallWorker(IInstallableExtension extension, Boolean perMachine, AsyncOperation asyncOp)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.