I'm using T4 templating to generate some .config files in a project I'm working on.
I've set up a pre-build task to look for all .tt files in the solution directory, and then execute the TextTransform command-line tool, so that the code is freshly generated on each build.
However, I'm now having "Access Denied" errors because (for example) when it tries to execute TextTransform on the Web.UAT.tt file, the Web.UAT.Config file is under source-control in TFS, and thus write protected.
Ordinarily I would select the .Config file in Visual Studio, and do the File->Source Control->Exclude From Source Control thing. Unfortunately, this does not appear as an option for any file which shows up as "nested" beneath another file!
i.e. I can exclude web.tt, but not web.config... I can exclude default.aspx but not default.aspx.cs.
Does anyone have any ideas about how I can exclude the lower level nested files from Source Control, but keep the top level ones?
Thanks!
I'm assuming you're using TFS here.
You're not going to be able to do this perfectly - since Visual Studio will automatically add any new item added to a project to source control. Your best solution is to look at using MSBuild and issuing a checkout for the output file before running the template (but then you'll likely have to check-in again afterwards). Having a quick look there is http://msbuildextensionpack.codeplex.com/ which I've seen mentioned for the purposes of doing this.
Failing that, there is another way.
The problem with this will be somebody else loading the project for the first time, their Visual Studio will automatically create the output file if they run the .TT - in that case, they would either need to repeat this process (from step 2) or would need to manually create a stub .config file of the correct name (I would suggest before even loading the project) so that the project sees it and doesn't attempt to re-source-control it.
Ok... I've used an adapted version of Andras Zoltan's answer.
Basically, what I ended up doing was as follows:
Now, when you build, you ought to see the newly generated files in the Solution, but without any checking in or out.
There are a couple of disadvantages of this method. First, you will have to do this for each .tt file in the project, and make sure that any other developers are doing the same. Second, is that you can now only generate the output files by doing a build!
I think longer term, I'll probably take Andras's advice, and write some sort of MSBuild script to either check out and check back in the output files, or at least to remove the "Read-Only" flag using < Attrib >.
Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With