Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Text Templates And Existing Files
 

Text Templates And Existing Files

hi,

i have 2 similar requirements/problems i'm working through:

the first requirementi have (like so many others) is to generate classes from database table definitions, the way its been done with our existing bespoke codegen tool is to have "code in front" and "code behind files", where:

  • the code in frontis for custom development and wont get overwritten
  • the code behind will get overwritten with the latest code when a developer regenerates.

what i'm wondering is whats the best way to do this in terms of codegen.

a custom action???

basically,

i need to check for the existence of a file:

  • if it exists, then ignore it
  • if it doesnt,then create it.

would it bepossible to use the conditional actions from SFT for this???

the second requirement is similar to the first but:

i need to identify if the file exists,

  • if not create it and add a line to it related to the file i'm generating,
  • if it does exist append a line to it?

any help would be greatly appreciated..

regards...

mickdelaney  Tuesday, June 26, 2007 8:41 AM
I would add a GAX boolean recipe argument that represent any flag you need to determine when to do things (i.e. overwrite or not a file) and then have a ValueProvider associated with. This value provider for example could walk to solution structure, looking for a given file and returning true or false.

Then in your action you can check for recipe argument values in code and decide whether to execute some code or not.

As you mentioned you could also use SFT conditional execution to make everything look prettier, that is to have some actions automatically execute or not based on an argument value.

Does this help?

-Victor.
vga  Thursday, June 28, 2007 9:12 PM

has no one else tried this?? would really appreciate some guidance here (excusethe pun!!!)

regards...

mickdelaney  Thursday, June 28, 2007 12:24 PM

Hi Mick,

There are not a rule about what you want to do, basically it depends in the level of granularity that you want to have in your package. So if what you want is the granularity, you could have a conditional coordinator which evaluate some arguments, in your case that arguments should have valueproviders which says if the file is already exists or not, etc. However if your focus is basically to resolve the requirement so, you can use an action in which you can make coffee there. You have to think in the granularity level and how much extensible will be your package.

hope it helps.

Jose Escrich  Thursday, June 28, 2007 3:12 PM
I would add a GAX boolean recipe argument that represent any flag you need to determine when to do things (i.e. overwrite or not a file) and then have a ValueProvider associated with. This value provider for example could walk to solution structure, looking for a given file and returning true or false.

Then in your action you can check for recipe argument values in code and decide whether to execute some code or not.

As you mentioned you could also use SFT conditional execution to make everything look prettier, that is to have some actions automatically execute or not based on an argument value.

Does this help?

-Victor.
vga  Thursday, June 28, 2007 9:12 PM

cheers victor,

thats want ithought. it sounds logical.

i'll need to be able to read in the text of a file and then append text to it also.

arethere any built in receipes & examples of this???

regards.

mickdelaney  Tuesday, July 03, 2007 9:01 AM

I done this type of feature (to make a step by step global SQL files in which i store all generated crud SPs for my mapping) using "not so specific" actions....

This way simplify the package file and you could reuse your actions later in other project.



To add line to an existing file, find it in project you want (with DTEHelper)... After that get the Document property as cast it as a TextDocument (ns EnvDTE)... Take a look after at the MDSN documentation (because i don't want say error from my mind)...you have to create an "EditPoint" from this TextDocument (EndPoint or something like this with CreateEditPoint method)... this edit point give you method (Insert; with a lot of others) to add text to the item... You have to save it after.


MephistoDark  Wednesday, July 04, 2007 7:59 PM

Hi Mephistodark,

yeah i've managed to figure out all the FileCodeModel etc stuff. Been looking at looks of examples from vs addin, its very comprehensive and will defo allow me to do what i want. also in the GATExlibrary there's some additional stuff thats helped me.

regards.

mickdelaney  Thursday, July 05, 2007 8:29 AM

You can use google to search for other answers

Custom Search

More Threads

• Bug in Microsoft.Practices.RecipeFramework.Library.DteHelper.IsWebProject
• Visual Studio doesnot show Designer because of a project referenced dll not loading correctly...
• how to re-enable register/unregister/quick register guidance package
• Use AddEntity recipe form HoL on existing porjects
• Action Condition
• Web application project template
• How do i use the project name entered in the VS wizard
• How do I automate the inclusion of source files in visual studio projects?
• Not able to install on vista x64
• Installing Web Serivce Software Factory failing