Is there any option of uploading code (from a zip file) to an empty VSTS team project?
I have used VSTS API(Projects) to create Team Project but i don't see any option there to push code to newly created VSTS project.
We can connect from Visual Studio to team project and check in code but i'm looking for some process which can add code to empty VSTS project without manual intervention.
any help/pointers would be appreciated.
First, you should uncompress zip file in an empty folder. Then commit and push the files into the new created repo.
Uncompress zip file:
string zipPath = #"C:\a\1.zip"; \\zip file you want to uncompress
string extractPath = #"C:\a\2"; \\empty path to extract files in zip
ZipFile.ExtractToDirectory(zipPath, extractPath);
Add the uncompress files into git repo:
For git repo
You can use REST API to add files and push to git repo.
Or you can use System.Diagnostics.Process to execute git commands, such as
ProcessStartInfo gitInfo = new ProcessStartInfo();
gitInfo.CreateNoWindow = true;
gitInfo.UseShellExecute = false;
gitInfo.RedirectStandardError = true;
gitInfo.RedirectStandardOutput = true;
gitInfo.FileName = #"path to git.exe"; \\such as D:\program files\Git\bin\git.exe
gitInfo.Arguments = "git remote add origin https://account.visualstudio.com/project/_git/repo";
gitInfo.WorkingDirectory = #"C:\a\2"; \\path where extract files in
Process gitProcess = new Process();
gitProcess.StartInfo = gitInfo;
gitProcess.Start();
string stderr_str = gitProcess.StandardError.ReadToEnd();
string stdout_str = gitProcess.StandardOutput.ReadToEnd();
gitProcess.WaitForExit();
gitProcess.Close();
For TFVC repo
You can use the commands.
Related
I have a desktop application to modify some xml files that are under source control. The program should be able to get the files, modify them and make a checkin. I already know how to do all that with tf; however, I don't know how to run the developer command prompt for visual studio using code. Also, the program will be installed in computers that doesn't have visual studio; therefore, they won't have the tf command anywhere. Taking into account all that, what would be the best way to run the following commands?
mkdir C:\Temp\PROGRAM
cd C:\Temp\PROGRAM && tf workspace /new /noprompt PROGRAM /collection:"http://myserver:8080/tfs/mycollection"
cd C:\Temp\PROGRAM && tf workfold /map $/my/server/route/to/map C:\Temp\PROGRAM
cd C:\Temp\PROGRAM && tf get
I know that there are some libraries to work with tfvc, but I haven't used them and don't seem as clear as running the commands. Any solution that manage to do the same as the commands above will be welcomed.
Create workspace
Map a folder from the server to a local folder
Download (checkout) all files in that folder (doesn't need to be recursive)
If possible to include in the solution:
Make checkin of files changed
EDIT
The code that I finally used is this
static void Load(string local, string server, Uri urlCollection)
{
Directory.CreateDirectory(local);
Workspace workspace = GetWorkspace(urlCollection, "MyWorkspaceName");
workspace.Map(server, local);
workspace.Get();
}
static Workspace GetWorkspace(Uri urlCollection, string name)
{
VersionControlServer vcs = new TfsTeamProjectCollection(urlCollection)
.GetService<VersionControlServer>();
try
{ return vcs.GetWorkspace(name, vcs.AuthorizedUser))}
catch(Exception)
{ return vcs.CreateWorkspace(name, vcs.AuthorizedUser)); }
}
According to your description, you want to pull down files from TFS server and then check in changed files programmatically.
You could use TFS client API to achieve this. Suggest you go through Buck Hodges's blog which shows how to create a workspace, pend changes, check in those changes.
Please refer Team Foundation Version Control client API example for TFS 2010 and newer
As for how to get files from TFS, there are also multiple samples in web portal, suggest you use the VersionControlServer.GetItem Method
Examples of usage:
// Get the latest Item for local path "C:\projects\myfiles.cs"
Item item1 = versionControlServer.GetItem("C:\projects\myfiles.cs");
// Get ItemId = 12345 for changesetId = 54321
Item item2 = versionControlServer.GetItem(12345,54321);
// Get the latest Item for server path "$/ProjectName/myfile.cs"
Item item1 = versionControlServer.GetItem("$/ProjectName/myfile.cs", VersionSpec.Latest);
You could also select a history version of source code to pull down, for the entire code, please refer below tutorials: Team Foundation Server API: Programmatically Downloading Files From
Source Control
Another way is using powershell script to handle this, please take a look here: Download files from TFS server with PowerShell
You can install on the computers the Team Explorer Everywhere, it gives you the ability to use TFS command line (the "tf" commands) without Visual Studio.
We are using TFS build and when I built the project in TFS build, it also creates a setup file.
For example, my application version is V1.2.3 (its from assembly.cs) the location of the setup file is C:\myproject\setup\setup.exe
Well I want to copy this setup exe into the following folder
C:\products\producta\ V1.2.3
So I just need to get version number to create a folder named "V1.2.3". For copying and creeating, i can make a batch file but i do not know how to get version number. TFS has some variables for example Build.SourceVersion
but these variables do not give me the product's version number.
How I can do this thing?
You have to write a script to do this.
1) Powershell script to read the build number from assemblyInfo.cs
$myAssemblyVersion = major.minor.patch -> Read from assembyInfo.cs
$versionWithBuildId = '{0}.{1}' -f $myAssemblyVersion, $Env:BUILD_BUILDID
2) Update the TFS internal build number from current build
Write-Verbose -verbose "##vso[build.updatebuildnumber]$versionWithBuildId"
After that you can use the "Copy Files" or "Publish Artifact" step.
With "Copy Files"
Target Folder = "C:\products\producta\$(Build.BuildNumber)"
With "Publish Artifact"
Artifact Name = "$(Build.BuildNumber)"
Path = "C:\products\producta"
I am trying to use Jenkins in combination with MSBuildExtensions and TFS to transform AssemblyInfo.cs
On my dev box, everything works, fine, including the connection to TFS, which returns the changeset number correctly.
When I check in a changeset, and try and build on the Jenkins server, I get an error and the build breaks on this command:
Resolve TF.exe path
TF.exe path resolved to: C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\..\IDE\tf.exe
TF Operation: GetChangeset
Executing C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\..\IDE\tf.exe changeset /login:myDomain\SomeUser,myPassword /latest /noprompt
C:\Program Files\Jenkins\jobs\DemoVersioning\workspace\VersioningDemo\VersioningDemo.csproj(513,3): error : Exit Code 100. Nothing Succeeded: Unable to determine the source control server.
In my msbuild script, this is the TFS command I am running on "BeforeBuild":
<TfsSource TaskAction="GetChangeset"
Login="myDomain\someUser,password">
<Output TaskParameter="Changeset" PropertyName="ChangeSet" />
</TfsSource>
I think this has something to do with the workspace being missing - but Jenkins pulls everything down fine, so shouldn't the workspace exist?
Some guidance would be appreciated as I am starting to go bald over this.
Supporting Material:
Can you do a TFS get without needing a workspace?
Solution 1:
By-pass the TFS voodoo, get Git for TFS, and run the below.
(This would be the equivalent of "svn.exe 'export'" if you know that world.
"C:\MyProgFiles\GitTF\git-tf.cmd" clone http://MyCoolteamfoundationserver:8080/tfs/ $/MySolution/
Solution 2:
Create the workspace and map it and then "get" the code.
Here is a .bat version that you would mimic:
set __MYWORKSPACENAME=CI_TEMP_WORKSPACE
set __BASEDIRECTORYFINAL=c:\ci_build_stuff\
MD %__BASEDIRECTORYFINAL%
CD %__BASEDIRECTORYFINAL%
set __tfExe=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe
"%__tfExe%" workspace /new %__MYWORKSPACENAME% /collection:http://my_super_cool_teamfoundationserver:8080/tfs/my_cool_projects /noprompt
"%__tfExe%" workfold /map $/MyTFSPath %__BASEDIRECTORYFINAL%\SXA
"%__tfExe%" get %__BASEDIRECTORYFINAL%\MyTFSPath\ /recursive /noprompt
set __BASEDIRECTORYFINAL=
set __MYWORKSPACENAME=
set __tfExe=
Further thoughts:
Checkout
http://msbuildextensionpack.codeplex.com/workitem/11709
That might have some built in workspace voodoo in it, that isn't there on the changeset.
Get the source code and look around, it'll tell you what's going on.
I see this one:
http://msbuildextensionpack.codeplex.com/SourceControl/latest#Solutions/Main/TFS/TeamBuild.cs
public class TeamBuild : BaseTask
{
private const string GetLatestTaskAction = "GetLatest";
private const string QueueTaskAction = "Queue";
private const string RelatedChangesetsTaskAction = "RelatedChangesets";
private const string RelatedWorkItemsTaskAction = "RelatedWorkItems";
I am trying to cleanup my workspace. I've created a separate reusable static library for the helper functions and another for the main project.
My directory structure is as follows:
SimplyStats/
SimplyStats/
externals/GoodStuffIOS
both the main project and the library project have been succesfully pushed/updated/committed to their respective bitBucket repositories.
But when i use XCode to push changes, i get the following dialog:
Notice that the Remote repository for the GoodStuffIOS project is at fault. The repository Organiser shows that the repositories are set up correctly. Whatever I do, I cannot fix that remote. How do I fix this?
EDIT: Here are the contents of my .git/config (starred the repo names)
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[branch "master"]
[remote "SimplyStats"]
url = https://************#bitbucket.org/**********/simplystats
fetch = +refs/heads/*:refs/remotes/SimplyStats/*
[submodule "externals/GoodStuffIOS"]
url = https://************#bitbucket.org/**********/goodstuffios.git
Navigate to the source folders, find the .git folder and navigate into it. There is a config file and that contains the urls of the remote repositories:
It should contain something like this:
[remote "origin"]
url = <remote-repo-url>
fetch = +refs/heads/*:refs/remotes/upstream/*
Verify, if it has the correct url. Try a git clone <remote-repo-url> in some temp folder.
Here's what i had to do to fix the problem.
Close the workspaces,
Go to Organiser/Repositories,
then for each relevant project, select in left column and remove by clicking '-'
quit XCode
verify/clean .git/config
verify/clean .gitmodules
reopen XCode
open workspace
I'm developing an iOS app with XCode 4.2 and latest SDK.
I have added to my project a folder with several files. This folder is a real folder in Finder.
When I try to commit those files I get the following message:
svn: Commit failed (details follow):
svn: '/Users/User1/Fuentes/iPhone/Desarrollos/TurismoCR2/TurismoCR2/Descripciones' is not under version control and is not part of the commit, yet its child '/Users/User1/Fuentes/iPhone/Desarrollos/TurismoCR2/TurismoCR2/Descripciones/021es.html' is part of the commit
How can I fix this error?
Probably I could add these files and folder manually but I don't know how (and I don't want to make a mistake).
You need to do:
cd /Users/User1/Fuentes/iPhone/Desarrollos/TurismoCR2/TurismoCR2
then:
svn add Descripciones/
Try this:
step 1:
svn ci
step 2:
Then vim or vi will be automatically offered by the svn (with svn diff file name) then type the required string or massage and save it.
Done.