Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.nuget folder why solutions have it?

Tags:

c#

nuget

at work we do not use nuget and even though in my personal projects i use it ,i dont understand why many solutions I download all have it,typically with 3 files

Nuget.config,exe and target.

Can somebody explain why people add this folder to their solutions?

thanks

like image 396
developer9969 Avatar asked Dec 19 '22 17:12

developer9969


2 Answers

That folder was a key player in NuGet package restore in the good old days (NuGet.targets is the proof). But since the new restore mechanism is in place, only the NuGet.exe is useful.

You might read more from NuGet.org,

https://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

Update:

The linked article was updated and moved to Microsoft Docs.

MSBuild 15 also adds NuGet package restore support if you read the above carefully.

like image 129
Lex Li Avatar answered Jan 02 '23 23:01

Lex Li


As of nuget 2.7+, this folder is no longer needed and can be safely deleted. Futhermore, if you use the Visual Studio command line prompt, you should be able to access nuget.exe from there, as well as, within Visual Studio from the Package Manager.

To enable automatic package restore in projects that used nuget 2.6 or before, you might need to manually delete the following from the bottom of your *.csproj files:

  <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
    <Error Condition="!Exists('..\..\packages\MSBuildTasks.1.5.0.214\build\MSBuildTasks.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\MSBuildTasks.1.5.0.214\build\MSBuildTasks.targets'))" />
  </Target>
like image 38
Jahmic Avatar answered Jan 03 '23 00:01

Jahmic