You will learn followings
- How can I clear the NuGet package cache using the command line?
- Unlocking files and folders locked by some employee on TFS
- How to get the nuget cache folder location programmatically
- Get TFS to ignore NuGet packages folder
How can I clear the NuGet package cache using the command line?
You can do this using Visual Studio menu on UI or by using command. You have two ways to do this. Let's check:
First Option:
Let's move with first option, we can clear our development computer's NuGet package cache using Visual Studio menu Tools → Options → NuGet Package Manager → General: "Clear Package Cache" button.

Second Option:
First, download the NuGet command line tool from here. Now, open command prompt and type cd to the directory to which nuget.exe was downloaded.
You can list the local caches with this command:
nuget locals all --list
You can clear all caches with this command:
nuget locals all --clear
In case of .Net core you can use following command to clear cache
dotnet nuget locals all --clear
Unlocking files and folders locked by some employee on TFS
Keep in mind that you will need the appropriate rights. The permissions are called "Undo other users' changes" and "Unlock other users' changes". These permissions can be viewed by
- Right-clicking the desired project, folder, or file in Source Control Explorer.
- Select Properties.
- Select the Security tab.
- Select the appropriate user or group in the Users and Groups section at the top.
- View the "Permissions for [user/group]:" section at the bottom.

Next way is:
If you login into the source control with the admin account, you will be able to force undo checkout, or check in with any file you provide.
Undo TFS code checked by another user:
You must have admin right and then by using below command you can undo code which is checked by other user who is not in company now. Use * if you want to undo all file with in given folder or in case of single file pass the name of specific file.
Syntax is:
tf undo {file path} /workspace:{workspace};{username}
Sample command are below
tf undo $/CmpProject/Project_2/MAIN/APP1.1/Encrypt.sln /workspace:WorkspaceName
tf undo $/CmpProject/Project_2/MAIN/APP1.1/* /workspace:WorkspaceName
If you have administrative rights to the collection, you can use the TF command located in the Visual Studio\Common7\IDE directory to do this without having to install another tool.
List all the workspaces associated with the user:
TF workspaces /collection:"http://tfsserver:8080/tfs/collection_name" /owner:owner_id
This will return the list of workspaces owned by the user and computer they are associated with
To delete a given workspace:
TF workspace /delete workspacename;owner_id /collection:"http://tfsserver:8080/tfs/collection_name"
Nutshell
If you are admin then login into the source control with your admin account, you will be able to force undo checkout or check in with any file you provide.
How to get the nuget cache folder location programmatically
While programming if I need to get from a .NET app (not .NET Core app) the list of directories where NuGet stores its packages. Let's see how to do this.
Next Option is:
In order to achieve this, you need to use the same code and libraries as nuget.exe does:
- Install nuget package NuGet.Configuration to your project.
- Add using NuGet.Configuration at the top of your file.
- Use the following code (which nuget.exe uses itself under the hood)
var settings = Settings.LoadDefaultSettings(null);
Console.WriteLine(SettingsUtility.GetGlobalPackagesFolder(settings));
Get TFS to ignore NuGet packages folder
We have to tell both NuGet and TFS to ignore the packages, because NuGet is trying to do source-control related stuff that it absolutely shouldn't be doing. So, you have to do two things.
First Option:
First, add a file named .tfignore to the solution folder (note the lack of s after the tf). Its contents should be as follows:
\Project
\Packages
\OtherStuffForIgnore
fool.cs
This tells TFS to ignore the package folder. You might think that this would also ignore the repositories.config file. But that's not the case but why?
Microsoft's approach is strange and mysterious. Actually, I think this is part of the NuGet described below, but if this is fixed in the future and you want to keep the repositories.config file instead of having VS regenerate it, you should use the following can There are:
\packages
!\packages\repositories.config
OK, so now thanks to our .tfignore
file, TFS is ignoring your packages. Everything is fine, right? No its WRONG, because NuGet is mucking around with your source control and adding the packages to your pending changes. So now let's tell NuGet to cut it out already.
Second Option:
Create a folder called .nuget in the root of your solution folder. Now, create a file called NuGet.config, and put it in this new folder.
- A nuget.config file containing the disableSourceControlIntegration setting.
- A version of the NuGet Visual Studio 2015 Extension that respects the
disableSourceControlIntegration
setting (versions from 3.2 onward will work)
The nuget.config file contents should look like, as it is given below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Now your packages should stay out of source control. Just remember to add the NuGet.config and .tfignore files to source control so they never get lost.
People also report that the .tfignore option was NOT working with the nuget.config setting it might be of interest - I followed following steps and it finally worked for me.
- Delete everything in my packages folder.
- Make sure TFS doesn't have any changes around that folder pending.
- Close Visual Studio.
- Re-open VS and reload your solution - using NuGet restore to re-populate packages Note no changes are pending for TFS source control.
No comments:
Post a Comment