可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
How do I get the latest version of my solution recursively like its done in the solution explorer context menu of Visual Studio? I want to do this from the command line or via a macro. I'm trying to automate a part of my daily routine by using a set of batch files. I am sure a lot of developers would love to have something like this.
tf get
only gets contents of a folder recursively (not solution). It does not look at project dependencies and so on. That won't work.
回答1:
TFS has a .Net SDK that allows you to create your own custom programs that interact with a TFS Server. You could write a small program that performs the task you need:
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("MyServer");
VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
WorkSpace[] myWorkSpaces = vcs.QueryWorkSpaces("MyWorkSpaceName", "MyLoginName", "MyComputer");
myWorkSpaces[0].Get(VersionSpec.Latest, GetOptions.GetAll);
回答2:
I agree that Solution Explorer will "by design" omit all those objects, but only if you do not include them as Solution items, which I believe you should include in your solutions, so that a newbie can open the solution, do a Get Latest, and know they have all the dependencies needed for that solution, and not have to learn how to do it via a command line tool, or use Source Control Explorer if they don't want to.
Including all the non-code dependencies as solution items (we organize the solution folders using the same folder structure as their source control folders) reduces "voodoo" knowledge required to open and compile the solution for new developers on a project.
It would be good if you could link entire folder trees to a solution folder in the VS solution.
回答3:
If you have dependent projects under a different folder. Use this to loop through all of the sub directories to grab the latest for each project:
Start in the main directory C:\Project\SupportingProjects
FOR /D %%G IN ("*") DO ECHO ..from....%%G && tf get C:\Projects\SupportingProjects\%%G
::Get the latest for the Main project
tf get C:\Projects\MainProject /recursive
In my case the MainProject folder contains the solution file and the project file.
I found this easy and simple.
More on the FOR command: http://ss64.com/nt/for_d.html
回答4:
Well... It looks like you have three options.
In your batch file, issue a tf get at each directory branch you want.
reorganize your solution so that all of the dependencies are under the same root path.
Use the visual way of right clicking on the loaded project and issuing the get command.
The only time it's actually solution aware is when the project is loaded in the IDE; or when it's loaded by the build servers.
回答5:
I know you mentioned batch files, but let me throw something else out for you.
I'm going to guess that you are using the 2005 version of TFS. 2008 has all of the scheduling stuff built in.
However, you could also use CruiseControl.net to do scheduled builds for you. I've used both TFS 2008 and CruiseControl and they both seem to work just fine.
回答6:
One more possible solution is to use powershell. The following link is to a code project sample which shows how to get a solution from TFS and build it locally. Powershell is a much better solution than regular batch files.
http://www.codeproject.com/KB/install/ExtractAndBuild.aspx
回答7:
Don't do this. VS is not nearly as smart as you think. (As evidenced by the mysterious & futile checkouts that everyone has experienced for 3+ product cycles, you & I included. This is not the mark of a reliable system!)
What you describe only works for project-to-project references. Running source control operations from Solution Explorer will "by design" omit:
- project-to-assembly references
- video, sound, PDFs, any other type of media that VS doesn't support but may play an integral role in the product
- MSBuild *.targets files that are referenced in your projects
- any files of any kind that are referenced from custom targets
- any 3rd party executables required by the build process
- etc
Just say no to incomplete synchronization. Down that path, only headaches lie.
Run 'tf get' with no path scope from the command line, or rightclick -> Get from the root $/ node in Source Control Explorer.