I have this setup:
$/Shared/nuget.config
$/Shared/.nuget
$/SomeTeamProject/nuget.config
$/SomeTeamProject/SomeTeamProject.sln
Using VS.Net 2015 Update 3
nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="$\..\..\Shared\.nuget" />
</config>
<packageRestore>
<add key="enabled" value="true" />
<add key="automatic" value="true"/>
</packageRestore>
</configuration>
I'd like to refer to the nuget.config file from Shared.
(I tried adding nuget.config to $/ but that's not allowed by TFS)
Added $/Shared/nuget.config as an existing item to SomeTeamProject but it doesn't seem to work.. It only works when I copy nuget.config from Shared to the SomeTeamProject folder.
It seems to ignore the referenced nuget.config file and creates a .packages folder in the SomeTeamProject folder..
A hard copy of nuget.config from the Shared Team Project works ok.
But a linked (add existing file) is not being used by NuGet for this solution:
The nuget.config file isn't used when you place it in "Shared" folder. You can refer to Configuring NuGet Behavior and specially Priority ordering section to see how the nuget.config file works.
And there is no way to simply add a link to get it work. The nuget only check the files in current folder or up level folder, it does not check the linked nuget.config file.
Related
I am trying to figure out how to override the package folder from the user folder to a custom folder location like inside my project folder
I have a webapi Core project with an appSetting.json
I read a few posts and may suggests using nuget.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<clear />
<add key="globalPackagesFolder" value="d:\\packages" />
</config>
</configuration>
I added in my WebAPI project which show along side with appsetting.json.
When I build the project, I see no package folder.
I also read about packages.config but I can't find that file anywhere.
Any help is appreciated.
Thanks
The nuget.config file should be placed in a directory one level above the project and then it will work.
For an example, the ConsoleApp152 folder is the folder which contains all your project files. And nuget.config file should be placed at the one level above the project files.
When you finish it, please close VS and then restart your project to enable this setting. And it will act on all projects in the directory level where the current nuget.config file is located and also all projects in the subordinate directories.
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.
We moved NuGet's packages folder to some other place and created a NuGet.Config file at the slns level:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="../.nugetPackages" />
</config>
</configuration>
We also have this in few of our csproj files:
<Import Project="..\..\..\Proj\packages\Microsoft.Azure.DocumentDB.1.7.1\build\Microsoft.Azure.DocumentDB.targets" Condition="Exists('..\..\..\Proj\packages\Microsoft.Azure.DocumentDB.1.7.1\build\Microsoft.Azure.DocumentDB.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use 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('..\..\..\Proj\packages\Microsoft.Azure.DocumentDB.1.7.1\build\Microsoft.Azure.DocumentDB.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\Proj\packages\Microsoft.Azure.DocumentDB.1.7.1\build\Microsoft.Azure.DocumentDB.targets'))" />
</Target>
And this too:
<Import Project="..\..\packages\PostSharp.4.2.17\tools\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp.4.2.17\tools\PostSharp.targets')" />
<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
<Error Condition="!Exists('..\..\packages\PostSharp.4.2.17\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://www.postsharp.net/links/nuget-restore." />
<Error Condition="Exists('..\..\packages\PostSharp.4.2.17\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
</Target>
My question is how to deal with such relative package paths in the csproj files to keep things generic (so we could easily move the package folder anytime anywhere)?
Is there maybe some variable we can use like $NuGetPackagesDir or something like that?
(We use Vs2015, NuGet 5.3 and TeamCity build server [I don't remember current version..])
You cannot really have a generic path and still use the NuGet tooling within Visual Studio since when you update a package the hint path will be updated by NuGet back to a relative path if you are using a packages.config file.
Whilst you could specify a global packages folder the hint paths will be relative to that path depending on where you put the solution.
The hint path problem goes away when you use a project.json file or have a new .NET Core style project that uses PackageReference elements in the .csproj file. If you are using a packages.config file then your .csproj file will have hint paths pointing to assemblies within the packages folder.
My application has the following structure:
lib
package1
...
package2
...
repositories.config
src
MyProject.Web
packages.config
...
MyProject.sln
NuGet.config
My NuGet.config file contains the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="disableSourceControlIntegration" value="true" />
<add key="repositorypath" value="../lib" />
</config>
</configuration>
From my understanding the disableSourceControlIntegration config option is supposed to tell visual studio to add the packages to TFS and the repository path is used to change the default location to the packages directory.
I have this setup and working fine. However when I right click on the solution file and say add to source control I can see the lib directory is ready to check-in in source control explorer. I thought this folder would be ignored and simply exists locally and then when you do a build of the project is would download the nuget packages locally.
I'd appreciate it if someone could tell me what I'm doing wrong. Thanks
Your config should look like following. See I have solution tag instead of config.
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Check this link out:
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
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\" />