I want to change NuGet package folder, but it does not change it.
What I do is creating file nuget.config:
<configuration>
<config>
<add key="repositoryPath" value="C:\projects\" />
</config>
</configuration>
I added this file in the solution folder (in same folder where is .sln file) or in the project folder and after that restart VS, but nothing happen.
I am using Visual Studio 2017 Community.
Change NuGet package location folder
Depending on what sort of project you are using this setting may or may not be successfully to change NuGet packager folder.
If you are using a .NET Framework project that has a packages.config file then this setting will change the nuget package folder to C:\projects\.
But if you are using a project.json file, then this setting will not successful. Because project.json project doesn't support repositoryPath config.
To change the nuget packager folder, you can you can set "NUGET_PACKAGES" environment variable. Just Set "NUGET_PACKAGES" = "c:\teampackages". Or you can place a NuGet.Config file next to the solution with the following content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value=".\packages" />
</config>
</configuration>
For the detail info, you can refer to this thread:
Dotnet restore does not honour nuget.config 'repositoryPath'.
Update:
I noticed that you are creating Xamarin.Forms project with Visual Studio Community 2017, the reference should be PackageReference, for this sort of project, you should use add below code to the .csproj file:
<PropertyGroup>
<RestorePackagesPath>D:\Test\packages</RestorePackagesPath>
</PropertyGroup>
Then restart Visual Studio, VS/NuGet will restore nuget packages to the D:\Test\packages, it works fine on my side, you can check my test sample:
Hope this helps.
In Tools/Nuget Package Manager/Package Manager Settings
Options
Related
Suppose we have a Visual Studio template that we would like to distribute within our organization. This template is hosted on an SVN server. I would like users to be able to point Nuget to the SVN location and get the template installed in the proper location just like any other package. Is this possible?
Is this possible?
We can do it but individuals do NOT recommend it.
How
According to the NuGet document:
Put simply, a NuGet package is a single ZIP file with the .nupkg
extension that contains compiled code (DLLs), other files related to
that code, and a descriptive manifest that includes information like
the package's version number. Developers with code to share create
packages and publish them to a public or private host. Package
consumers obtain those packages from suitable hosts, add them to their
projects, and then call a package's functionality in their project
code. NuGet itself then handles all of the intermediate details.
However, the Visual Studio Template is a file with the .zip extension, which could not be recognized by NuGet. Even if we point NuGet to the SVN location, NuGet still can not recognize it.
To resolve this issue, we have to create a NuGet package to include this Visual Studio Template .zip file, like:
<files>
<file src="TestDemo.zip" target="Tools\TestDemo.zip" />
</files>
Besides, there is another question, when we install this nuget package to the project, this Visual Studio Template .zip file would be downloaded to the \packages folder in the solution folder. We have to move it to the Visual Studio Templates folder.
So, we have to add .targets with copy task in that nuget package to copy zip file to the Visual Studio Templates folder.
The content of .targets file:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopyTemplate" BeforeTargets="Build">
<Message Text="Copy Template to template folder."></Message>
<Copy
SourceFiles="$(SolutionDir)packages\MyTemplatePackage.1.0.0\Tools\TestDemo.zip"
DestinationFolder="$(USERPROFILE)\Documents\Visual Studio 2017\Templates\ProjectTemplates"
/>
</Target>
</Project>
Finally, the .nuspec file like following:
<?xml version="1.0"?>
<package >
<metadata>
<id>MyTemplatePackage</id>
<version>1.0.0</version>
<authors>Tester</authors>
<owners>Tester</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package description</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2018</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
<files>
<file src="TestDemo.zip" target="Tools\TestDemo.zip" />
<file src="MyTemplatePackage.targets" target="Build\MyTemplatePackage.targets" />
</files>
</package>
Then pack this .nuspec file, add this nuget package to the SVN location, add the SVN location to the nuget package source, you can install this nuget package to the project, and build the project, Visual Studio will download that nuget package and copy .zip file to the Visual Studio Templates folder.
I have created a sample test nuget package and it work fine on my side with Visual Studio 2017, you can test it on VS2017: https://1drv.ms/u/s!Ai1sp_yvodHf2Vax7TzuC6HQUD5w
Why not recommend
Just as you can see above, it is not easy and simple to do this, we have to do a lot of things to create that nuget package. What`s more, in order to get the template we have to create a project and install that package and build the project. It pulls in too many extra operations. Besides, when you change anything in the template, you have to re-create this package and install it.
Since this template is hosted on an SVN server, you can just check it to the Visual Studio template folder, this will be more effective.
Hope this complicated answer helps.
I'm working on a Xamarin.Forms PCL mobile app in Visual Studio 2017, using project.json for package management (I'm not using PackageReference, since Visual Studio 2017 is required for that, and some of our team are still using Visual Studio 2015). I have multiple projects within the solution, and I have multiple branches of the project, like so:
MobileApp/
packages/ <<--- (I want nuget packages to be installed here)
Branches/
DevBranchSolution/
MobileApp.sln
nuget.config
ProjectA/
ProjectB/
I want all my (projects / solutions / branches) to be able to reference packages from a single location, so you'll notice I've added the packages folder at the root level in the MobileApp folder. I have a nuget.config file per solution that looks something like:
nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="..\..\packages" />
</config>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="CustomPackagesLocation" value="..\..\packages" />
</packageSources>
<disabledPackageSources />
</configuration>
In Visual Studio when I right-click on the solution, click "Manage NuGet Packages For Solution...", and install a package (e.g. Newtonsoft.Json), I would expect that it would install those package files inside my MobileApp/packages/ folder, the location I set in the solution's nuget.config. But it doesn't. Instead the files are getting put into the global NuGet packages location, which is %USERPROFILE%\.nuget\packages.
Why? Shouldn't my nuget.config file be overriding that? I have verified that when I go to Package Manager Settings, the location of CustomPackagesLocation is correct, but apparently the repositoryPath setting doesn't seem to affect anything.
I also noticed that inside the project.json.lock and Project.nuget.targets files, the package folder is set to the global NuGet packages location (the %USERPROFILE%/.nuget/packages one). Why? Where is it pulling this value from??
Why? Where is it pulling this value from??
The default packages directory for Project.json file is %USERPROFILE%/.nuget/packages and project.json project doesn't support repositoryPath config now. This is the reason why you have changed the repositoryPath, but NuGet still put packages into the global NuGet packages location. You can refer to the same issue on GitHub.
If you want to change packages default location for project.json, you can set "NUGET_PACKAGES" environment variable. Just Set "NUGET_PACKAGES" = "....\packages". Or you can place a NuGet.Config file next to the solution with the following content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="globalPackagesFolder" value="..\..\packages" />
</config>
</configuration>
See NuGet.Config reference for details on config section.
I had a very similar problem where it wasn't using the packages folder for a class library. For some reason my csproj file had set for a few assemblies. I removed this line and did a update-package -reinstall -project myclasslibrary and it worked again just fine.
I'm not sure what set the HintPath in the first place.
I'm working on a NuGet package that adds a step to the build process by using a .targets file.
I need to reference other files from my NuGet package in order to complete the build successfully.
In the past, I've used $(SolutionDir)packages\MyPackage and all has worked fine.
However, I was just playing around with the VS 2017 RC, and I noticed that my package was installed in the global NuGet package directory, not in the solution folder.
Is there some macro that I can use from MSBuild, that contains the path for the NuGet packages folder? It is a requirement that I maintain compatibility with VS2012.
The $(NuGetPackageRoot) macro points to the package root.
You can use an alternative method that create a NuGet.Config file in the root of the \Solutions\ folder to set the package repositoryPath of VS 2017 RC, add to NuGet.Config the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="$\..\Packages" />
</config>
</configuration>
For the repositoryPath setting, you can specify an absolute path or relative path (recommended) using the $ token. The $ token is based on where the NuGet.Config is located. In this case, you package will install in $(SolutionDir)packages\ folder, you can used $(SolutionDir)packages\MyPackage for Visual Studio 2017 RC. It`s also maintain compatibility with VS2012.
Problem: TFS Build Server (v2013.4) is not honoring the repositoryPath setting in the nuget.config file.
I have nuget auto restore enabled with a custom repository folder. On my local dev PC this works perfectly using Visual Studio 2013.4. I am not using the old auto restore (with nuget targets file, nuget.exe and build directives), instead I am using the new way with Nuget 2.7+. My custom folder "nuget-packages" is excluded from source control with a .tfignore file. All packages get auto downloaded to this folder.
Local folder paths:
c:\ source \ nuget-packages\
c:\ source \ Solution Dir \ .nuget \ nuget.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
<config>
<add key="repositoryPath" value="..\..\nuget-packages" />
</config>
</solution>
</configuration>
I can view my TFS build log and I see that the build process is calling nuget restore command, and downloading the packages, but in looking at the build server local source directory, the nuget packages are downloading into the default folder ( \Solution Dir\packages ) so my builds are failing with assembly reference errors.
It could be this bug. Updating NuGet to 2.8 will fix the issue.
I am trying to change the location of the default package folder for NuGet
I read many posts including the documentation of the NuGet 2.1 Release Notes, the new config for NuGet version 2.1 as the following:
<configuration>
<config>
<add key=" repositoryPath" value=" C:\myteam\teampackages" />
</config>
...
</configuration>
I also read the following thread, Is it possible to change the location of packages for NuGet?
But this configuration doesn't work?
The only config work is the old one which is as the following:
<settings>
<repositoryPath>C:\myteam\teampackages</repositoryPath>
</settings>
I am using Visual Studio 2012 Update 1 that including NuGet Package version 2.1
Steps to reproduce:
in solution directory, create a file "nuget.config"
edit nuget.config and add:
<settings>
<repositoryPath>C:\myteam\teampackages</repositoryPath>
</settings>
Delete the default packages folder
In visual studio, right-click on Solution, and select Manage NuGet
Packages Install a package (any package)
Verify that package was downloaded to C:\myteam\teampackages
delete the downloaded package in C:\myteam\teampackages
change the nuget.config to the following:
<configuration>
<config>
<add key="repositoryPath" value="C:\myteam\teampackages" />
</config>
</configuration>
Try to install any library again.
I find the library installed in the packages folder not my folder???
>>steps to reproduce:
>>in solution directory, create a file "nuget.config"
From the release notes it looks for nuget.config in the following order
.nuget\nuget.config
Recursive walk from project (.nuget) folder to root
Global nuget.config (%appdata%\NuGet\nuget.config)
So if nuget.config is in the project/solution folder it won't be honored. Can you try moving it to .nuget folder and reload the solution.
It works when you place a \ at the end of the path:
<add key=" repositoryPath" value="C:\myteam\teampackages\" />