This project is read-only.

T4MVC.tt.settings.xml - Access Denied

Nov 15, 2012 at 8:57 PM

I am in a TFS environment. With this comes the read only attribute on files I have not checked out. When running the T4MVC.tt, I get access denied errors. I have to check out the settings file in order for it to work. Is there any way to make this automatic? I have spent a lot of time trying to find information on this, and have come up short. I have been using T4MVC for a long time and some comrades of mine are being put out (I don't mind so much checking out the settings file, but they are getting annoyed), please help! I have never really got into the inner workings off this, is there any way to get the contents of the settings file, delete and recreate? I am not sure if that is a solution or if it is possible.

Thanks in advance :)

 

Nov 15, 2012 at 11:57 PM

Hmmm, I'm not sure why that file would work differently from the others. It sounds like the same thing reported here.

Nov 16, 2012 at 12:04 AM

Oh I see, this file gets created quite differently, via explicit code in T4MVC.tt (in the SaveChanges(Manager manager) method). That just calls XmlWriter.Create, so there is no logic to check out the file. For the other files, it goes through Damien Guard's logic, which has explicit code for CheckoutFileIfRequired. So it should be fixable by doing something similar for the xml file.

Do you want to take a crack at it?

On a side note, my understanding is that the latest TFS no longer keeps files locked, not require explicit checkout, so this would be a non-issue.

Nov 16, 2012 at 12:28 AM

Out of curiosity, why does it need to save the settings file at all? Isn't that kind of backwards?

Nov 16, 2012 at 2:01 AM

Ya, that's a great question! What it's supposed to do is that if you don't have a file at all, it creates a default for you. And if you do have one, it should leave it alone. So there may be a bug in there. @mswainatwork, since you added this feature, any chance you can take a look? Thanks!

Nov 16, 2012 at 1:12 PM

Actually, it does more than just create the file, it ensures that the file is current and accurate. I did not use the file manager to save the file because the file is not created in the same way that the other generated files are. I will, however, look at exposing and implementing the locked file check that david mentioned.

The file is saved all the time because the settings class currently does not know if the file is up to date, it just has default values and attempts to read values from an xml file. I would have to add a check to prevent saving if it managed to read all properties from the settings file. I will look into a way to detect changes and only save when necessary.

Nov 16, 2012 at 9:56 PM

Ok, @mswainatwork's fix is in 3.0.1 (thanks!). @jxmiller, can you please give it a try and confirm that it works for you?

Nov 16, 2012 at 10:30 PM

So far so good. My testing thus far revolved around manually setting the (settings) file to be readonly, then running the main t4mvc.tt. I then also added an action result to make sure it did ~something, and still no problem. The settings file remains readonly.

If I have any problems, or hear of anyone else having issues I will report back. Thanks so much! A+, would read again!

Nov 16, 2012 at 10:33 PM

Another interesting test is to yank some random setting from the xml file (e.g. ViewsRootFolder) and run the template. In this case, it should get regenerated (I tested that it it works fine), but the more interesting case is when it needs to be checked out in TFS.