How to remove the nuget Packages folder from TFS? - tfs

I just went through a dll hell. Turns out that TFS has been synchronizing packages, and I ended up with two versions of Microsoft.Web.Optimization and its dependencies at once. NuGet was convinced that I have the newest versions installed, and even reinstallation changed nothing. But at the same time, my projects wouldn't build or, if they'd build, they wouldn't start, complaining that they can't find the library version given in the manifest.
I managed to solve it by uninstalling the packages from NuGet console, physically removing their folders from the hard disc, and then doing a fresh build (which re-installed the missing latest versions). But the package folders I deleted manually are still sitting around in the Source Control Explorer. And I can't delete them, the Delete button is greyed out when I select one of them. I am afraid that they will come again when I get newest version next time.
How do I prevent it? I would like to remove them from the solution completely. In the worst case, it would be OK to ignore them, but as they are on a level above the projects, I can't enter them into a project's .tfignore file, and Visual Studio didn't let me add a .tfignore file to the solution itself.

Would it be an option to not checking in the Packages folder to TFS? NuGet now supports automatic package restore, which automatically restores packages on build.
Here is doc for migrating to this new model: http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore.
And this may save you a lot of hassle with checked-in packages folder.

Arguably best answered in this post:
https://stackoverflow.com/a/40409464/1690217
The NuGet documentation provides instructions on how to accomplish this and I just followed them successfully for Visual Studio 2015 against VSTS (Azure-hosted TFS). Everything is fully updated as of Nov 2016. This also still works for Visual Studio 2017 RTM (March 2017).
I added the following files as explained above:
.tfignore
\packages
!\packages\repositories.config
.nuget\nugget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
I had to delete the packages folder and checkin the delete, then package restore will kickin and rebuild the folder but VS will no longer automatically add it to source control.

Related

How to debug project.json/nuget build issues?

Visual Studio 2015 Enterprise
Nuget.exe 3.4.4.1321
Project: Windows Forms Class Library
OK I have project.json file setup in my solution and this builds fine. I have NO IDEA how msbuild finds the packages project.json asks for, but that's fine.
I check the files into TFS 2012 (ya I know, our company won't upgrade yet)
TFS fails to build. Says "type cannot be found..."
How on earth do you DEBUG these sorts of issues when you have NO IDEA where MSBuild even LOOKS for packages?
I can GUESS where MS Build may be looking, but how can I confirm this?
csproj hintpaths had their drawbacks, but at least you KNEW where msbuild would look for your package
with Project.Json I have no idea where msbuild is looking!
The package IS there on the build server, right where I expect it to be. How to tell msbuild.exe where to look for packages?
According to your error message, it seems that something wrong with the reference using. For trouble shooting your issue, please try the following.
Please use Package.config for your project to install packages in TFS build. Check if it works to make sure your assemblies and packages are fine.
If Package.config doesn't work. Please provide the detail steps for me to reproduce your issue.
If package.config works but project.json doesn't works. Look at this document: Converting a csproj from package.config to project.json
To debug a build: https://msdn.microsoft.com/en-us/library/jj635150.aspx?f=255&MSPPError=-2147217396
Note: To always use the latest version of the package available, you could add the following to Nuget.config file. So it will get the latest version when you use packages.config. The Nuget.config file is at: C:\Users\UserName\AppData\Roaming\NuGet
(nuget spec dependencies, get latest version?)
<configuration>
<config>
<add key="dependencyversion" value="Highest" />
</config>
</configuration>
project.lock.json will report the resolution path for nuget packages.
This will appear at the VERY BOTTOM of the project.lock.json file:
sample:
"packageFolders": {
"c:\\nuget_packages": {}
Adding this key in nuget.config tells nuget where to restore packages:
<config>
<add key="globalPackagesFolder" value="c:\nuget_packages" />
</config>
This ONLY works for nuget 3+ with project.json file, not with packages.config

Visual Studio 2015 Nuget Restore Problems for Version 1.0.3 of Newtonsoft.Json.dll

I have a solution which was working with Visual Studio 2015 Community in a machine. That machine was crashed and I can not access the source codes over there any more.
However the source codes were checked into TFS. After I got new machine, I got all latest source codes from TFS.
The issue is that this solution in new machine has a lot of compile errors.
Visual Studio 2015 could restore some of the references. However I have a complain like this -
Clicking button Restore will have this error -
I don't think I have used a version of 1.0.3 of Newtonsoft.Json.dll directly. I deleted the package folder and all project bin and obj folders. The recompile still can not fix it.
What can be done to fix this problem?
Have you also delete the NuGet.Config file in the packages folder? If you did it, Visual Studio will try to do the MSBuild package restore instead of Automatic Package Restore.
By default, the NuGet.Config file instructs NuGet to bypass adding
package binaries to source control. Automatic Package Restore will
honor this as long as you leave this file in place. Note that
NuGet.Config only has an effect when using Visual Studio to integrate
with Team Foundation Server (TFS).
You should also manually remove references in all your projects to the Nuget.targets file. The following article outlines in more details: https://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore
If you still can't fix it, try to use the Command-Line Package Restore

NuGet adds Packages folder to the solution. Should it be part of Source control?

I am using NuGet to add packages to my solution. NuGet added a Packages folder to my visual studio’s solution root folder. The concerning part is that the “packages” folder is not part of source control. That means the source code comes from TFS, but the project references come from a folder that is fed by external source. People can put malicious code in the packages folder and build the application.
I like to understand how my other colleagues that get the source code from the TFS source control can build the project with packages folder not being part of the source control?
We did have a similar problem where our build server wasn't allowed to have internet connection, so couldn't download packages. We started with creating our own NuGet Source, which was simply a shared folder with all packages copied to it. The visual studio projects would of course use these packages rather than packages hosted on www.nuget.org
I must say that we scrapped this idea because of the overhead of doing it as our package usage increased.
My advise is that if you are worried about packages downloaded at build time, store the packages folder on source control.
NuGet supports automatic package restoration so your colleagues who use this feature will automatically download required packages. There is a policy at nuget.org that prevents user to delete or update exact version of package once it is published so it can support package restore without any interruptions - see this answer for more detail. If you are using other package sources than nuget.org than you should check their package deletion/update policy because it may be different.

Reinstall Microsoft Visual Studio Asp.net MVC 5 Scaffolding extension

I hade a problem with scaffolding in Asp.Net MVC 5 and Visual studio 2013
I tried to reinstall the extension "Microsoft Visual Studio Asp.net MVC 5 Scaffolding" by first uninstalled it. But I cant find any way to install it again.
I tried to repair visual studio. - no luck
I tried to uninstall visual studio and install visual studio, but the extension is still missing
Do I have to reinstall the PC or is there a quick fix?
I wanted to add to Chrille's answer.
The PendingDeletes can be found in
HKEY_USERS\<SID>\Software\Microsoft\VisualStudio\12.0Exp\ExtensionManager
And
HKEY_USERS\<SID>\Software\Microsoft\VisualStudio\12.0\ExtensionManager
And I found the AppData in my local and Roaming app data.
Here's what I did. It was a bit more involved than what everyone else was reporting. I tried doing a repair in the Control Panel, it ran for several hours and then failed. Perhaps my problems were that I installed VS2013 sp1 and then upgraded it to SP4 before I removed "Microsoft Visual Studio Asp.net MVC 5 Scaffolding."
I downloaded and installed Visual Studio Premium with Update 4 and then did a repair using that file, but the extension was still missing. I then found the AspNetWebFrameworksTools_VS12_ENU.msi in the en_visual_studio_premium_2013_with_update_4_x86_dvd_5935086.iso and did an uninstall and a reinstall, but the extension was still missing.
I extracted the packages\WPT\AspNetWebFrameworksTools_VS12_ENU.msi file from my .iso file using msiexec. In order to get the .msi file to extract successfully, I also had to place the *.cab files from \packages\WPT into the same folder I was extracting the .msi from. Once I'd extracted my msi file, I went into it's folder structure and found the Scaffolding stuff. It was in Dest\Microsoft ASP.NET\ASP.NET Web Stack 5\VS_12_COMMON7_IDE\Extensions\Microsoft\Web\Mvc\Scaffolding folder.
Once I had that, I still didn't have a .vsix file that I could install into Visual Studio. So what I did was create my own .vsix file. I did a little research on the web and created a file called [Content_Types].xml, it's literally called that. I renamed the file extension on several .vsix files that I had downloaded on my system to .zip and looked inside them to see what the contents of my [Content_Types].xml should look like, here's what I came up with:
<?xml version="1.0" encoding="utf-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="dll" ContentType="application/octet-stream" />
<Default Extension="pkgdef" ContentType="text/plain" />
<Default Extension="vsixmanifest" ContentType="text/xml" />
<Default Extension="txt" ContentType="text/plain" />
</Types>
I then zipped up [Content_Types].xml, extension.vsixmanifest, and Microsoft.AspNet.Scaffolding.Mvc.5.0.dll to a zip file called Microsoft.AspNet.Scaffolding.Mvc.5.0.zip. I then renamed that .zip file to Microsoft.AspNet.Scaffolding.Mvc.5.0.vsix. I then was able to install the extension using this .vsix file that I created.
I found that uninstall the AspNetWebFrameworksTools_VS12_ENU.msi in the vs2013 ISO. And install it.
So here's what I did...
1) I uninstalled the scaffolding through Visual Studio.
2) Deleted the registry from:
HKEY_USERS\<SID>\Software\Microsoft\VisualStudio\12.0\ExtensionManager\PendingDeletes
3) Went to Control Panel > Programs
4) Select Microsoft Visual Studio Ultimate 2013 > Hit Change
5) Choose Repair.
Pretty simple, but a little time consuming
Fixed it by deleting pendling delete in the registy + deleted AppData for Visual studio
AppData will be recreated at startup of vs
Have 7zip installed.
Download the full iso of visual studio.
extract the iso to a folder.
Go to \packages\WPT within that folder.
Run AspNetWebFrameworksTools_VS12_ENU.msi
Uninstall.
Run AspNetWebFrameworksTools_VS12_ENU.msi
Install.
That should do it.
To verify, create a new MVC project, and try to add a scaffold item. Don't verify with an existing project, because that may be a whole different problem.
I was missing the MVC controllers in scaffolding (only able to select Web API 2), then after removing MVC 5 scaffolding to reinstall I could not get it installed again.
I found downloading the .iso for VS 2013 update 4, extracting to a folder, then running AspNetWebFrameworksTools_VS12_ENU.msi to uninstall, then again to reinstall, then rebooting resolved both issues. I am now able to add controller, and I have MVC 5 controllers to choose from.
What worked for me was to remove the Registry keys, the AppData and the folder in this location C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions. After this, I repaired the VisualStudio from Programs and Features in control panel. I was desperate because even I uninstalled and re-installed again and the extension was not visible.

nuget, download uncommitted dlls

I made a checkout of my project from a different location, now I noticed that I didn't commit the dll files from /packages, can I get nuget to download them?
The only way to do this right now is to is to remove the reference from packages.config and reinstall those packages. We're planning to support this scenario in the future (more info here http://nuget.codeplex.com/workitem/165).

Resources