tf.exe authenticate for vsts - azure-devops

I am trying to list all the workspaces and trying to authenticate tf.exe with vsts using the below commandline.
tf workspaces /Collection: https://[account].visualstudio.com/defaultcollection /login:USername,Password
The vsts account is backed by Azure Active Directory synced with an on-prem AD.
It works fine when I have connected to the vsts from visual studio and then running the above tf.exe command without the login switch.
But, when I use the login switch for tf.exe and use the same credentials that I use in visual studio it throws
TF30063: You are not authorized to access https://[account].visualstudio.com/defaultcollection
TF30063: You are not authorized to access https://[account].visualstudio.com/defaultcollection
What I am trying to achieve is that I am going to provision a server and then not going to login to visual studio and want my tf to work as it works when logged in to the visual studio online account in the team explorer of my visual studio.
I am an admin of the vsts account and have full right on everything. If there are other ways of doing this possibly authenticate TF.exe using PAT token that would work as well.
I would use tf.exe again for a checkin command from automated builds.
Any help in solving this would be appreciated.

There is the Check in changes task in TFVC Build Tasks extension that you can use it to check in changes. Also, you can call TF command to check in changes during the build process, it uses build service account.
On the other hand, you can create a console application to check in changes through TFS API (Workspace.CheckIn method), then call this app through command line.

I was having the same issue (TF30063) when running tf.exe. For me the solution was:
Exit all running instances of Visual Studio
Rename %LocalAppData%\Microsoft\Team Foundation\7.0\Cache to %LocalAppData%\Microsoft\Team Foundation\7.0\Cache_old (or you could delete it; but I wanted to preserve the original so I had the option restore it when going back into VS). NB: the 7.0 varies according to which version of TF you're using.
Navigate to my project's folder pushd c:\projects\vsts_tfvc_repos\Project123
Run tf /collection:myinstance.visualstudio.com /workspace:%computername%
/login:myMicrosoftAccount#example.com,myPassword to initialise the session under the correct account
Thereafter, everything worked as expected...

Related

tf.exe TF30063 unauthorized (VS 2022)

I had to change my corporate password which we also use for Azure access. I rebooted and logged in into the account again. I can access Azure TFS from Visual Studio without a problem. However, tf.exe get . does not work anymore because apparantly I am unauthorized. I checked the internet/SO but the credential manager didn’t seem to hold any credentials I could clear and %LOCALAPPDATA%\Microsoft\ does not contain a Team Foundation folder where I could delete any cache.
When I try to use a personal access token (PAT), then instead of two "denied"s, I only get one:

Azure DevOps Visual studio build task fails with "access denied. Please make sure you're running the application as administrator"

I'm working with a Windows forms application and tried to run the build on Azure devOps.
The nuget tasks run fine and restores the packages.
But, the Visual studio build task fails with following error.
access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT
According to your screenshot, it appears that you are using the self-hosted agent.
To run the application as Administrator in pipeline, you need to change the agent service account to Administrator.
Generally when we configure the agent as a service, we need to specify an account, which in your scenario should be an Administrator account.

Create a workspace from Powershell run within VS Team Services build

I am writing a Powershell script as part of a Visual Studio Team Services build, this build uses a hosted build controller. The script is intended to check out a file, make changes then check it back in.
In the script I am trying to invoke the tf command to create a new workspace but I'm having authentication issues. The command
& $tf vc workspace /new $tempWorkspaceName /collection:https://mycollection.visualstudio.com/
produces the error:
TF30063: You are not authorized to access https://mycollection.visualstudio.com/.
How can I access TFS from my Powershell script without embedding logins or passwords in the script? Can I access TFS within the context of the build agent, which itself logs in to TFS? Or is there another way I should be doing this?
Note that I haven't used the TFS Power Tool cmdlets as it is a hosted build server. Using the TFS RestAPI also doesn't appear to be an option as there is no facility to check a file in or out.
Check Allow Scripts to Access OAuth Token option of your build defition
Append /noprompt /loginType:OAuth /login:.,$(System.AccessToken) to your TF command (arguments)
About TF Command, you can check this article.

How to import a project from Visual Studio Online to GitHub?

I have a couple project in Visual Studio Online (VSO), which I would like to move to my GitHub account. In VSO all projects are not publicly-readable. You must be authenticated using Microsoft Account (MA).
I tried to use the GitHub Importer (https://import.github.com/new) to do that. The importer asked me for read-only credentials to reach out to my project. Unfortunately, it cannot go through authentication event though I provide my MA credentials.
Is there anybody know how to import a project from Visual Studio Online to GitHub? Is it even possible?
Okay. I figured it out. You must enable the alternate authentication credentials as described in the following article. After that the importer starts doing its job:
https://web.archive.org/web/20161204015026/https://www.visualstudio.com/en-us/docs/integrate/get-started/auth/overview
If you're importing from Azure DevOps, don't use your account credentials while importing. Instead goto Azure Repos, select your repo which you are importing, then click on Clone and then click on Generate Credentials and then use those credentials in GitHub importer.

log access to code repo in visual studio online

When using visual studio online, we want to ensure that contractors or developer working on project could only check-in and check-out using our given laptops.
Has anyone found a way to restrict access to code from a certain machines in Visual studio Online?
Can we somehow log who checked code out and from which machine at what time?
There is currently no way to restrict access to VSO by IP address. It is something we are considering. What you can do is to enable two-factor authentication in your Azure Active Directory tenant.
There's no way to currently log who has checked out code. The closest you could get would be to periodically query for the workspaces in the account if you are using TFVC. There's no way for you to track clones of Git repos.