How to keep people from checking in generated file in TFS2010? - tfs

I've got a VS/TFS2010 project in which we use a generated file. Here's how it works:
There's a pre-build event that creates the file (foo.cs)
The file is included in the project.
The file is NEVER added to TFS version control.
It works great, except... People have an unfortunate habit of accidentally checking in the file. This, of course, breaks the system.
Are there any good ways to prevent this from happening? Can I at least set up some kind of watch mechanism to alert me if it does happen?

You'll need to install the Team Foundation Server Power Tools, which will include the "Forbidden Patterns" check-in policy. This will allow you to prohibit a file from being checked in based on regular expression applied to the server path.
This will allow you to simply add the full server path of the file you wish to ensure does not get added. For example:
^\$/TeamProject/Folder/foo\.cs$

I was researching this exact issue today and found this, which may be of some help: How to ignore files/directories in TFS for avoiding them to go to central source repository?
Not sure if 2010 has made this easier or not.
(Apologies, this should probably be a comment, but I don't think I have enough rep to comment.)

Related

Why in TFS I cannot apply a label on files listed in Changeset Details window?

As in subject:
Go to "Find Changeset" option.
Find a changeset.
Double-click on changeset to open Changeset Details window.
It gives a list of all files that have been checked in within given changeset.
Why I cannot apply a label on those files from that level where I have them all in one place? Especially, that very often they are part of different solutions and projects, so normally I would have to create a label for one file and then search and add one by one to the existing one.
It is so inefficient!
Is it some bug or lack of functionality? If the second - it is hard to believe MS guys forgot about such handy function.
How do you deal guys with such situation?
EDIT - to clarify my reasoning:
If I use jessehouwing's method - yes, it works and it's simple.
But then when I search in the future for that label and want to see what code was included, it gives me a list of all solutions - even those totally unrelated (IWP and PDPRO are the unwanted ones):
If I use it my way - it gives me that:
I think it looks cleaner and gives directly the information of what solutions and files underneath where included at the time when I put stuff into Production environment and applied corresponding PROD label.
The feature you're looking for doesn't exist. generally a single file or group of files at a label doesn't make a lot of sense. While it's possible to "scope" labels in TFVC, it's only possible through the commandline.
generally you'd create a label at the repo or branch level at the specified changeset. That will include all files, including the ones you just checked in. Creatign such label is relatively easy from the source control explorer, though you need to copy the changeset number:
It's unclear to me why you'd only want the changed files to be included in the label, maybe you can elaborate a little more on that requirement.
Update: What you desire isn't possible from inside VS and isn't simple from the commandline either. I suppose that with a bit of Powershell Magic against the TFS Client Object Model you can do this from the commandline and it should also be possible to build this as a Visual Studio Extension (or maybe suggest it to the author of the TFS Source Control Explorer Extensions.

How to deal with files that are relevant to version control, but that frequently change in irrelevant ways?

.dproj files are essential for Delphi projects, so they have to be under version control.
These files are controlled by the IDE and also contain some information that is frequently changed, but totally irrelevant for version control.
For example: I change the start parameters of the application frequently (several times a day), but don't want to accidently commit the project file if only the part dealing with the start parameters has changed.
So how to deal with this situation?
A clean solution would be to take the file apart, but that isn't possible with the Delphi IDE AFAIK.
Can you ignore a specific part of a file?
We're using Subversion at the moment, but may migrate to Git soon.
In our case, it's rare for a developer to make a meaningful change to the .bdsproj, .dpr, .res files. So we reject the commit (pre-commit hook in subversion) unless special tags: [add project file] or [add res file] are present in the commit comment. This prevents "frivilous" changes to those files.
SVN/git cannot "know" which bits of the file are important, and translating what is important for you to commit or not into file "bits" would be difficult (especially when you don't know exactly how the information is structured within it). The most practical solution is to check the changes that have been made to the file and decide whether to commit them or not to the repository.
You can decide which bits of the file you want to commit with git. This is not, however, the automated process you seem to be looking for.
For the specific case of startparameters: the DDevExtentions plugin of the well known Andreas Hausladen allow for the start parameters be stored separetely of dproj file. See more details about DDevExtensions on his site.
EDIT: If I remember correctly, this feature was created just because he had that exact problem with start parameters and version control.
I would not save the .dproj files directly in version control, but rather provide a default file which should be renamed by the user to get the flawed Delphi working.
Use the --assume-unchanged option on git update-index <file> as described here and stackoverflow/what-is-assume-unchanged.
You could make simple aliases for the those who need it made simple.

Why TFS doesn't add some DLL in Bin Directory?

When I added a whole solution in TFS, it didn't add one dll, I then have to add it manually.
Is there something that prevents it from doing so ?
How did you add the solution? The Add Items button will exclude a number of items through the filters you see in the dialog. There are two tabs there : Included & Excluded. When adding things to source control this way, you'll need to check the excluded tab for anything caught by the filter like 3rd party libraries.
If you used Add Solution to Source Control, I'm not entirely sure. If the dlls were in a project or a solution folder they should have been added. Again, if you give more details (step by step) I can help a little more.
Considering only 1 DLL was rejected out of several, it sounds like a TFS bug. I know don't be shocked... there are actually a few of these.
For example, I have text files get removed from my solution when I use "undo checkout". Unfortunately that problem is unpredictable, so no fix yet.
TIP: Always diff your solutions and projects before you check them in.
As Ryan said when adding to the repository certain filers are applied, e.g. you have to explicitly add dlls to the repos. See this
The problem is that you have binded the project to IIS. And IIS block access to some DLLs.
If you using Visual Studio 2012 and you can't add the files to TFS just exclude a file, add to repository, include file and check in.

Is it possible to configure TFS not to mark file as read-only?

The title pretty much says it all.
I'm using a RFT, VS addin that allows me to edit a proprietary data file with a GUI. The problem is that this file doesn't show up in VS and when I start editing it via the GUI, VS doesn't check it out automatically (probably a bug of the VS addin). So, I've to check it out manually before editing it, otherwise the addin will crash when trying to save the file (because it is read-only), and sometimes will also corrupt the local working copy of this project.
Everything would be much easier if TFS didn't mark the file not checked out as read only.
Do you know if there is a way to instruct TFS to keep all the files as not read-only?
No. You can exclude it from source control, but that's probably not want you want.
I have the same issues with TFS. Our project has a few small SQL Server database files that we have chosen to put under source control. We handle the read only issue by adding these to the post build statement on the project build. I suppose we could have done this pre-build as well.
attrib $(TargetDir)*.mdf -r
attrib $(TargetDir)*.ldf -r
It has been a while, but - I think this link is actually the answer to that.
When you do a check out, what you are actually doing is saying “TFS, I
would like to edit the version of the file that I have already
downloaded, is that ok?” TFS then looks at that version, and tells you
if you can edit it or not (based on your security permissions at that
point in time and if anyone else has placed a lock on the file). If
you can edit the file, the TFS marks the file as read/write on your
local machine and allows you to proceed.
I.E: When I r.clicked the project and selected "Check out and edit", the r/o flag was automatically removed, and I could compile (with both pre/post events) and then "check in" again.
Well you can get latest to a samba share, which eats the readonly bit.

TFS 2008 checks out code automatically on edit

I am working on a Visual Studio 2008 project that is already added to TFS server.
I am not sure which settings and policies have been configured for the TFS (this is done by a separate dept, not developers)
Every time I make an edit to a code file , the file is checked out automatically (without explicitly checking out the code file myself)
Please help me locate this setting or policy because it is not very useful at the moment. Sometime you want to make a local change to try out something, and not necessarily check out the code....
It is in Options\SourceControl\Environment
Checked out Items: Check out automatically
change it to
Checked out Items: Prompt for exclusive checkouts
or your preferred action.
Unfortunately, with TFS it puts read-only locks on your files to PREVENT you from editing the file without checking it out first.
I cannot stand this decision. What you'll have to do is allow TFS to check out the file, then "Undo checkout" on it later if you don't want to check it out.
Make sure you have shared checkout enabled, exclusively locking files is the path to madness. ;)
I think this is a feature not a problem. If you change a module and it's under source control, you are now "out of sync" with the repository. If you exit (and the default behavior is to save) - and come back later - the file is not what everyone else is seeing. This can be dangerous.
For example: back in the days of VSS - on a Friday afternoon I had to "put out a fire" and debug a problem in, Prod Environment, so I changed the connection string in the appropriate config file. Another developer had the file checked out - so I did the usual workaround to mark the file read-only so I could save it. I figured out the problem and informed the user. This was in fire-fighting mode - so I didn't consider the fact that I now have production connection string in my dev configuration.
Monday mornign I come in and open up the solution. Is there any feedback telling me the config file is pointing to production? No I have to remember.
If the file is checked-out however - that icon is indicator to me that "flags" the fact that the files have been modified. I don't quite understand the "big deal" in having to right-click the solution and say "un-do pending changes"
Or if you want to save them, as the down-voted suggestion by aleichtle.wordpress (I don't understand the down votes - I think it is an excellent suggestion) explains, you can shelve the changes. This will remove the check-out and also save the changes on the server.
Version Control systems are a critical and important component of the software development life cycle. It is important to consider your "process". You may need to make adjustments as you use a different tool ("When in Rome"....)
It may be difficult to make the adjustment - but there are often good reasons the tool works the way it does.
You can make a shelveset of the code allowing you to make a change to the code without affecting the rest of the development.
You can do this by right clicking on the file and selecting shelve pending changes.
I'm running Windows 7 and VS 2010.
From Windows Explorer, you can
- right-click on your project's main folder
- Choose Team Foundation Server
- Choose Workspace
- Remove the active Working Folder (bottom of the screen).
I belive this removes the bindings to TFS, and you're free to wreak havoc on your code at will.
Close your solution.
Unplug your network cable.
Open your solution.
Visual Studio will tell you that TFS is not available and will open the solution "Offline".
Plug your network cable back in. VS should not take the solution "Online" until you explicitly ask it to.
You can then make any changes you like. When you attempt to save files it will tell you they are readonly - just overwrite them.
If you decide you want to check them in, take the solution Online by right-clicking it in the Solution Explorer.
Otherwise, just delete the local copy of the source when you're through with it.
You can remove binding to source control from file menu.

Resources