Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS 2008, remove file from source control but leave it in the project

We are using Scott Hansleman's suggestion for multiple web.configs from his post here. The problem we have is that we have to check out the Web.Config. If we remove it from the project, when we publish, no web.config is pushed. So we need to remove the source control bindings just from the web.config, but leave it in the project, and have the rest of the project still held under source control.

The issue is that source control makes the file read only until you check it out. We need to be able ot overwrite it with the prebuild events, preferably without having to check it out. Is there a way to remove the bindings from that file only, and still leave it as part of the project?

Thanks.

like image 353
Josh Avatar asked Sep 04 '09 14:09

Josh


People also ask

How do I delete a file from Source Control in TFS?

To delete an item In either Solution Explorer or Source Control Explorer, browse to the folder or file that you want to delete. Select the items that you want to delete, open their context menu (right-click), and choose Delete.

How do you unbind Source Control in Visual Studio?

Right-click your project or project suite in the Project Explorer and then click Source Control > Unbind From Team Foundation Server.


2 Answers

By adding a new file to solution explorer, you will get the little plus sign indicating it is due to be added to source control. Then, right-click and choose "undo pending changes". This will cancel the add but leave the file in your project.

If that doesn't work I suggest one of the following methods:

  • Use the Attrib task from the MSBuild Community Tasks project to remove the read only flag.
  • Use the Exec task in MSBuild to invoke tf.exe and checkout the file.
like image 147
Tim Booker Avatar answered Oct 12 '22 15:10

Tim Booker


You should leave the file in source control. Otherwise you'll run into several issues:

  • changes won't be versioned. 'nuf said.
  • it can't be branched or merged, even though web.config is one of the files that's most likely to vary between parallel dev/test/production environments
  • changes you make locally won't propagate to coworkers without manual workarounds
  • developers setting up an environment for the first time won't get the file at all
  • Team Builds won't contain the file, so neither will your deployments. (surely you're not deploying directly from the desktop?!)

Note that the state of individual files is stored entirely on the TFS server. ('tf properties' dumps this metadata if you're curious) Only projects & solutions have bindings actually written into the file. And even those are dummy entries that tell VS "don't worry about me, just ask TFSProvider, it'll know who I am and where I'm supposed to be." While there are many other quirks in the VS project system that give me endless headaches, in this case it's your friend. Don't circumvent it.

Best options:

  1. Edit your build script to toggle the read-only attribute before/after modification. If you're using the "copyifnewer.bat" script from the linked blog post, it should literally be one extra line. Even if you want to keep things entirely declarative within the MSBuild makefile, it's barely any work with the help of 3rd party tasks.

  2. Use the File -> Source Control -> Exclude feature. After applying this setting, the file remains under source control, but will no longer be subject to automatic checkouts/checkins by the active solution. In other words, you can edit the file locally to your heart's content without affecting anyone else, but if you want to commit (or shelve) your changes you'll need to do it from Source Control Explorer or the command line.

Option #1 has the advantage of being a very quick fix for your existing setup. The downside comes from maintaining several copies of web.config.* Same reason why copy/pasting code is bad: if you change one, you have to go change all the others -- or worse, forget and let them drift out of sync until strange bugs force you to revisit the issue. This could be improved by changing the process so that there's only 1 "master" web.config and the additional copies only contain differences (via a textual diff engine, XSLT transforms, programmatic manipulation in Powershell, etc). Of course, that's more work.

Option #2 avoids #1's problems with very little overhead. (the engineering process itself is unchanged; only difference is how the Visual Studio UI behaves) This advantage is critical if you make changes to web.config at all frequently. Downside is that there is no built-in way to track variations on the "master" file. If the only diffs are dirt simple, eg a connection string or two, you may find it easiest to stick with just one "master" and let people make ad hoc changes on their dev machines. There are even tools to do this for you, such as Web Deployment Projects (easy) and the IIS Deployment Tool (complex). In any case your actual deployment should be automated and source-controlled, of course! If heavier customizations are required than these tools are capable of, then you'll probably want the hybrid master + transform approach described earlier.

like image 26
Richard Berg Avatar answered Oct 12 '22 14:10

Richard Berg