Programmatically update files in a tfs workspace - visual-studio

I am working on an extension for visual studio to update a project.
The situation is a follows:
We create a new project from a template.
We put the solution in tfs
We change the project which was used to create the template. The project on the tfs server still needs te be updated.
We publish the project to a folder. I now want to update the files in the TFS repo with the current files in the publish folder
I thought of the following approach:
In the application we have all the project stored that are on the TFS server. When I want to update a specific project I select the project from the database. Next I load this project from the TFS server and create a new checkout for this project. So far so good. The problem arise when I copy the files from the published folder to the new checkout. Files that are already registered in the workspace get marked as changed but the files that are new are not added.
The only solution I can think of is to add all the files through the TFS SDK. But this seems pretty heavy to me.
So I got a couple of questions:
Is this the right approach to update
the project?
Is there any other way to add the files to the workspace instead of adding all files through the TFS SDK?
Thanks!

Don't do a blind copy of the files. Instead, have your program iterate through them one by one.
First, update your workspace with the latest from TFS.
Then, for each file in the source directory:
If the file exists in the target directory, "pend edit" the file, then copy it.
If the file does not exist, copy the file, then "pend add" the file.
When you've finished, check in all pending changes in the workspace.

Related

Visual Studio/TFS check-in migration

Is it possible to copy checked in files to a specific folder using a build definition or script? For example, if a check-in a file that is in a folder in TFS, on check-in can I copy that file to a server that has the same folder structure?
TFS
$/Website/files/index.html
Copy To
\ws-file01-dv\files\index.html
You could easily setup a TFS Build that is triggered on Check-In (CI Build) that simply does a Get Latest then copies the source to a file share.
You would have to modify the DefaultTemplate.xaml, by default it already downloads the source to the Build Agent Working Directory, you just need to add a Copy Folder activity that copies it to the target file share. If you've never customized a build workflow before I recommend reading the ALM Rangers Guidance to learn how: http://vsarbuildguide.codeplex.com/

Automatically include newly added files when pulling from GIT

User 1: creates a new class and commit and push that to git.
User 2: does a git pull. newly created class file gets downloaded but not included in project. Has to right click and do "Include in project"
Is there a way to automatically include a newly added file while doing pull from git?
Do I need to commit any other file (.csproj/.sln) to solve this issue?
IDE: Visual Studio 2010
The project files, .csproj, keep track of which files are loaded in a project. So yes, you will also need to commit the updated project file to the repository in order for User 2 to have the file added to their project as well.
In my experience, even if Visual Studio is open, it will recognize the changed project file and ask if you want to reload it. When you reload it, your project should have the new file loaded.
As an aside, there is a great blog post on why you should get fetch/merge instead of pull

TFS 2010 - Deleting a folder in Visual Studio solution before check-in of changes

We are using TFS 2010 and facing a problem with deleting a folder inside of a solution in Visual Studio.
In the latest version of checked-in code, the directory in question has files in it.
One of the developers decided to move the files in that directory to another location within the solution. He then tried to delete the old folder but go the following error:
This operation cannot be completed.
You are attempting to remove or delete a source-controlled item where the item is either exclusively locked elsewhere or otherwise unable to be deleted from source control.
Does anyone know what the problem is with trying to do this and is there a way to get around it?
You cannot delete a folder that has pending changes on any of its children (including if any of those children are being moved out of the folder - they're still children until that changeset is checked in.)
You'll have to do this in two steps: first, move the children out of the folder and check those changes in, then delete the folder as a separate changeset.
If the folder you want to delete exists on your local machine, just add a new file to the folder from within the Visual Studio IDE (it doesn't matter what type of file). Then you should be able to delete the folder from within VS.
If the folder was deleted from your local machine, create a new one with the same name and then follow the above steps.

Visual Studio and TortoiseHg: folder not visible in VS

I created a C# project and added it to source control (mercurial). I can edit files in VS, commit it and push it using TortoiseHg. It goes to the server. When some one pulls they get the files.
In my visual studio I added a folder and a file inside that folder. I used TortoiseHg and it saw the new file in the new folder. I committed it and pushed it.
However, now someone pulled the latest code from the server - and they got the new file (it is visible through windows explorer), but when they open the solution in VS, they don't see the file.
Does someone have an idea what is wrong here? or things I should check? Thank you for the help.
P.S. I have visual studio 2010 express (so I can't use the VisualHg plugin).
Visual Studio caches changes to the solution and project until an explicit save or a build. In your comment:
In my visual studio I added a folder and a file inside that folder. I used TortoiseHg and it saw the new file in the new folder. I committed it and pushed it.
I see that an updated .sln or .vcproj file was not mentioned and checked in. Did you see an update to either of these files via TortoiseHg? If not, make sure to build or save your project after a change like this.
Did you make sure that the Visual Studio Project File or Solution file is being updated and committed?
VS solution contains projects and each project select managed files by metadata(***.vcproj file). It's not the way include all files from root directory.
So, your co-workers can see new added files by in following two ways.
1) share project file(***.vcproj)
2) manually add files in each person's VS instance.

Make visual studio deploy a folder's content without having to update it in the project

In my web project I often have a number of files in my app_data folder. These files can vary from time to time (example translation files get a new language, lucene index gets updated and gets a new file name etc).
Visual studio only adds files to the deployment process if the files are seperately added to the project. So if a file has been added on disk, but not in the project, this file will not be copied to the server...
Is there a way to make VS add all files in a folder to the deployment process without me having to update it manually?
You can use a post build event to copy the contents of a folder to the build target.
This should get you started:
http://visualstudiohacks.com/general/customize-your-project-build-process/
Wow I just saw this was asked in 2009...I hope you figured this out already :)

Resources