Turn off formatting for T4 template generated code in VS2017 - visual-studio

I've been running into an issue with Visual Studio 2017 where a T4 template that is generating a bunch of C# classes from metadata is auto formatting the files based on the settings in Visual Studio's C# formatting options. I have changed these options and verified that the changes are reflected in the generated code. Basically what is happening is the T4 code generation completes and then Visual Studio begins to open every single file that was just generated and format it.
I've turned off formatting for the C# language in Tools and Options and disabled .editorconfig files just in case it was picking up one of those, but the template generation seems to ignore this. The problem is that these T4 templates generate ~2000 files which are then formatted which causes TFS to check out the file and eventually crashes visual studio about halfway through the formatting. Is there an option somewhere I'm missing to turn off formatting for generated code? This was not an issue prior to our recent upgrade to VS2017.

The default setting for Visual Studio 2017 is that it doesn't do anything to template files on the onset, so in order for this to happen it should be something you've added to your VS environment. Few things to check...
Any Visual Studio extensions or features. T4 is not well supported so a lot of the extensions and features out there have bugs in them. It maybe that the software provider hasn't thought of your problem yet and you should raise a bug with them. If your using an extension or feature to assist in your software development of T4 then try a different one. Additionally extensions or features not related to T4 also format files. An examples are Productivity Power Tools or Resharper
Under the properties of your template files check the Custom Tool value. It may not seem like the obvious choice, but occasionally if this is not set to TextTemplatingFileGenerator or TextTemplatingFilePreprocessor, you need know why it's not set that way. There might be a perfectly good reason for why its set differently, just so long as you know what that reason is
Normally templates use the *.tt extension, however there are many different acceptable extensions that suit different occasions. Make sure the extension isn't named the same as an existing extension, that formats files in its own way
If the features for C# are off, you might want to consider turning off all formatting features one by one incase the templates files are being considered as part of a different language or under a different option. Start with Tools > Options > Text Editor > Basic > Advanced > Pretty listing as an example. That may give you a clue as to where the setting is being affected.
HTH

Related

Enabling opening and closing tag guidelines in Visual Studio

I've recently started using Visual Studio quite heavily since starting to develop in .Net
I really like the intellisense as it increases my productivity by allowing me to code faster. Previously when authoring CSS I would just use Notepad ++ and I got very used to some of the little features that this awesome text editor possessed however, now that I am doing the bulk of my work in Visual Studio 2013 I want to try and avoid having too many environments open at once. With this in mind, there is one feature inparticular that I would like to try and replicate in Visual Studio when editing CSS or indeed any other type of code.
In Notepad ++ it automatically includes a sort of guideline which runs down the page between the opening and closing tags of elements as shown below:
My question is, how do I replicate this behaviour in Visual Studio 2013 as the currently setup I have at the moment isn't as clear/productive as you can see below:
Any help would be greatly appreciated.
There are a couple of free extensions you can use to do this. These will run on any of the Visual Studio versions except Express, which does not support extensions.
You can duplicate this with the Indent Guides extension.
You can also use the Structure Visualizer Feature of the Productivity Power Tools.
Note: The backgrounds in the example are different because they are taken on different machines with different themes.

Prevent comment conflicts in strings.resx (Visual Studio 2010)

Suppose an international team of developers, using various flavors of Visual Studio 2010 (understand: in different languages), and working on a versioned project.
Every time one of them makes a modification on the Strings.resx, Visual Studio happily generates the file with localized comments. Every time two or more of them do so at the same time, some pretty annoying conflicts appear, which not only are time consuming, but also are completely pointless. Developers get angry and all.
How can this be prevented? Is there a way to tell Visual Studio not to regenerate those comments, or to drop them altogether?
I don't know how to prevent Visual Studio generating localized comments in the .Designer.cs file which backs every .resx file. And I'd certainly like to know.
Until someone finds out, you'll have to setup Visual Studio in English (or whatever language is shared by most of your team) everytime you want to change the resources.
You can do that in Tools > Options > Environment > International Settings (you need to restart VS).
When programming, I don't mind setting up everything in english, rather than in my native tongue, because exceptions and error messages are almost always easier to google when they are in english.
HTH

Can I use different brace styles in different projects/solutions in VS2008?

I'm working with a couple of open-source projects that use different C# brace styles, and I'd like to configure VS text formatting to use different styles for each project so I can use Ctrl-K-D to reformat source code.
Is there any way I can configure Visual Studio 2008 to load a particular set of text formatting preferences along with a particular solution file?
As far as i know, there is no way to do this natively in VS 2008 (or even 2010 for that matter)
There is a resetsettings command line switch in Visual Studio which you can use to indicate what settings it should start up with. This works in 2005 and i presume it would with 2008 as well though i have personally not tried it with 2008. If you just make a bat file using this method as indicated here, that might be one workaround to your problem.
Also, there is an option to do a macro based solutions that might help you that i remember looking at in the past.You can probably check out this site which indicates how to do something very similar to what you are looking for

What T4 editing tools exist?

I don't use T4 templates often; usually when I do it is editing those of other projects (specifically SubSonic & T4MVC). The experience is always quite unpleasant (and this is certainly why I don't use them more often).
These are the tools I know of, and neither of them quite fit the bill.
Clarius Visual T4.
Does not support Visual Studio 2010. Their blog mentions work ongoing, but that was 2 months ago with no updates since. Their support forum is filled with spam and questions about when VS2010 will be supported.
Most of the projects I work on are in Visual Studio 2010, and the templates I deal with require themselves to be run in the Visual Studio host (as they access project information through VS's automation object model). This is why I am looking for a VS2010 compatible editor.
Tangible T4 Editor
The first time I attempted to use this, I thought Visual Studio 2010 had crashed. Turns out I didn't wait long enough (it took over 2 minutes for the editor window to appear). Call me picky, but this alone puts me off of this tool.
I have a modified T4MVC template that works. After I install Tangible's T4 editor, the template fails with several errors. If I then uninstall Tangible's T4 editor, the template works again. So it would seem something about the editor changes the behavior of T4 in Visual Studio. Perhaps obviously, that's entirely unacceptable.
Are there any other T4 editors I missed? Does anyone else use these tools, encounter these same issues, and successfully work with them?
I should also say, the most important feature for me is simply to distinguish between code that runs as part of the template and code/text that gets output. Everything else is gravy.
DevArt has released a T4 editor add on for Visual Studio. It is free and it works well. They do not appear to have a version for Visual Studio 2012 yet, however.
I have also come across a ReSharper plugin for editing T4 files, but I have not used it and cannot comment on how well it works (or does not).
Check out the T4 Toolbox.

Syntax coloring for VBS file in Visual Studio with a different extension

A program we work with in my office can be automated through VBScript Files, yet the files are saved with an extension *.RVB other then *.VBS. I'd like to use Visual Studio as my editor/debugger, which is working. Yet it is not coloring the code like it does if I have a *.VBS file open.
Under Tools->Options->File Extension I added "RVB" and set it's editor to Microsoft Visual Basic, yet it is still not applying any syntax highlighting to my file. What am I missing?
I realize this might be beyond what you had in mind. However, I see no acknowledgement to your solution so I am going out on a limb here. You could create a language extension and totally control all aspects of the coloring. This is easily transfered to 2010 (the example is in 2008) but remains relevant.
http://msdn.microsoft.com/en-us/vstudio/bb851701
In this video, Hilton Giesenow illustrates a simple working Language Service. He begins by building a simple scanner colorizingsing based on regular expressions, then expands on this to implement the Managed Babel framework, integrating MPLex and MPPG directly into the Visual Studio build as well.

Resources