Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent needing to add NuGet.exe to source control

Some context:
I've followed the tutorial on using NuGet without committing packages with some success. After working around this NuGet issue by manually adding <RestorePackages> and a <Import ...> for the nuget.targets file things were working.

However, once I cloned the repository with Mercurial, I got the following error when building:

Unable to locate 'C:\...\Visual Studio 2010\Projects\MyProject\.nuget\nuget.exe'

This makes sense, because my ignore pattern prevented me from checking in the exe file. From this related SO question I inferred that it's not uncommon to have this file in version control (or is it?), but really I'd prefer not to commit NuGet.exe to version control if I can help it.


Question: Is there a convenient way to prevent needing to check in NuGet.exe?


I've tried some Google-fu, skimming the documentation, and fiddling with the NuGet.targets file, no luck so far. It seems preferable if I could just dynamically point to the NuGet.exe of the particular environment that's building the solution.

I know I could just add the exe file, but I'd prefer to know if there are other ways to handle this or know why there are no viable alternatives.

Update:
The nuget.targets file holds some relevant xml:

<!-- only (relevant) parts of the xml shown below --> <DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe> ... <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">     <Task>         <Code Type="Fragment" Language="cs">         <![CDATA[         try {             OutputFilename = Path.GetFullPath(OutputFilename);              Log.LogMessage("Downloading latest version of NuGet.exe...");             WebClient webClient = new WebClient();             webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);              return true;         }         catch (Exception ex) {             Log.LogErrorFromException(ex);             return false;         }         ]]>         </Code>     </task> </UsingTask> 

I'm unfamiliar with the workings of .targets files, but this seems to be along the lines of what I'm looking for. With my cowboy-coding hat on I tried changing the false to true in the DownloadNuGetExe element, but this didn't work as expected (with or without the condition attribute).

like image 302
Jeroen Avatar asked Aug 18 '12 20:08

Jeroen


People also ask

Should packages folder be in Source Control?

Should I check in the Packages folder in the Source Control to make them available for peers? The answer is "NO". You should not checkin packages folders since this will increase the size of the repository and it will become overhead when taking the latest (since the size of the packages folder is in the MBs).

How do I disable NuGet package?

Go to Tools -> Options -> NuGet Package Manager -> General -> Package Restore. The first option disables restore itself, while the 2nd option disables on build restore. NuGet tries to restore to make sure that the packages were not deleted from disk or that the assets file (which helps the intellisense) is not deleted.

Do I need .NuGet folder?

nuget folder is used as a cache for packages downloaded to speed up project restore and compilation. It can safely be removed.

Where does NuGet EXE get installed?

Install the official nuget.exe in your PC. Create a Symbolic Link here: %localappdata%\microsoft\winget\links. Make the nuget.exe globally available for your user to call it from anywhere, since the aforementioned directory should be present in your user's PATH variable.


1 Answers

Just checked: nuget.targets is an msbuild file. And you were on the right way, in:

<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe> 

Change the value to true:

<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe> 

But you must restart Visual Studio or reload the solution (see comments) after this to take effect.

like image 87
Pavel Bakshy Avatar answered Oct 05 '22 10:10

Pavel Bakshy