8

I created an ASP.NET MVC 4.5 application.
Now I want to change packages.config to mypackages1.config. A simple renaming of the file.

I edited .csproj file and renamed as mentioned.
I renamed packages.config file as mentioned.
I edited repositories.config and made changes as mentioned.

But, when I issued Install-Package somepackage, it created a new packages.config file.

Is there a way I can rename my packages.config file? I don't yet have .nuget folder in my solution.

2 Answers2

17

This is not supported. You cannot change the packages.config file to any arbitrary name.

The only thing NuGet supports is to have the packages.config file named after the project file itself. This allows multiple project files (.csproj) to be in the same directory. So if your project is called FooBar.csproj you can have a packages.config file named:

packages.FooBar.config
Matt Ward
  • 47,057
  • 5
  • 93
  • 94
  • This is exactly my scenario! I want to build the same source code using different configurations (.NET 3.5, .NET 4.5, PCL...) and these require different NuGet packages in turn. I'll try this out in the next couple of days. – Drew Noakes Dec 29 '15 at 14:47
  • This NuGet feature is not well documented. It is briefly mentioned in a [release note](https://docs.nuget.org/release-notes/nuget-2.8). Paul Betts uses the feature in [ReactiveUI](https://github.com/reactiveui/ReactiveUI/tree/master/ReactiveUI) – Matt Ward Dec 29 '15 at 14:54
  • Finally tested this in my [metadata-extractor](https://github.com/drewnoakes/metadata-extractor-dotnet) project and it works perfectly. Thanks. – Drew Noakes Jan 02 '16 at 22:20
1

Try to enable nuget package restore for your solution, then the nuget folder will be created. In the Nuget.Targets file rename the packages.config to the name you altered. I haven't tried it out but try this may help you. Also you must make sure the newly downloaded must create an entry in that file alone not the packages.config it creates.

Venkatesh
  • 1,204
  • 1
  • 10
  • 18