Exclude nested items from a control source

I am using T4 templating to generate some .config files in the project I'm working on.

I set up a pre-build task to search for all .tt files in the solution directory, and then ran the TextTransform command-line tool so that the code was just generated for each build.

However, I now have "Access Denied" errors, because (for example), when he tries to execute TextTransform in the Web.UAT.tt file, the Web.UAT.Config file is under source control in TFS, and is thus protected from the record.

Usually I selected the .Config file in Visual Studio and did File-> Source Control-> Exclude From Source Control. Unfortunately, this does not look like an option for any file that appears as "attached" under 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 on how I can exclude lower level file attachments from Source Control, but keep the upper levels?

Thanks!

+6
version-control tfs visual-studio-2008 t4
source share
2 answers

I assume you are using TFS here.

You cannot do it perfectly - because Visual Studio will automatically add the new item added to the project to the original control. The best solution is to look at the use of MSBuild and issue a control file for the output file before running the template (but then you will probably have to register again). A quick glance at the http://msbuildextensionpack.codeplex.com/ , which I mentioned earlier, for the purposes of this.

Otherwise, there is another way.

  • Delete the output .config file from the source file and check (it is better to use Source Control Explorer for this).
  • Run .tt manually from VS, it will add the file again - now it should have a plus sign next to it.
  • Again, in the Source Control Explorer, right-click on this "new" file and select "Undo Pending Changes." You now have a file on disk, but not in the source code.
  • Now TT can be launched, the file is part of the project (and therefore will be published or something else), but it is not under the control of the source.

The problem with this will be that someone else loads the project for the first time, their Visual Studio will automatically create the output file if they run .TT - in this case they will either have to repeat this process (from step 2), or you You will need to manually create the stub.config file with the correct name (I would suggest, even before loading the project), so that the project sees it and does not try to rename it.

+2
source share

Ok ... I used an adapted version of Andras Zoltan's answer.

Basically, what I ended up with was the following:

  • Click on the .tt file in Visual Studio and change the "Custom Tool" line in the properties so that it is empty. This will remove the .config file from the solution.
  • Add a new, empty element to the solution, called any output file for .tt (like Web.UAT.tt β†’ Web.UAT.config).
  • Select the newly added file and exclude it from Source Control as usual (File β†’ Source Control β†’ Exclude).

Now that you are creating, you should see the newly created files in the solution, but without any verification or exit.

There are several drawbacks to this method. First, you will need to do this for each .tt file in the project and make sure that other developers do the same. Secondly, you can now only generate output files by building!

I think in the long run I will probably take Andras advice and write some kind of MSBuild script to either check, or check in the output files, or at least remove the Read-Only flag using <Attrib> .

Thanks!

+2
source share

All Articles