33

I want a custom directory structure for my Content in my MVC project for example:

\Content
    --\js
    --\css
    --\img

Is it possible to tell a NuGet package to install scripts in the Content\js folder? For example the jQuery package so that the jquery-1.6.js file is installed in the Content\js folder?

3
  • 12
    I think this is a big oversight in Nuget. There's a lot to love in ASP.NET MVC, but I've never liked the Content and Scripts folders. I used to change these to more standard css, images and js folders, but I feel like I have to stick with Contents and Scripts now that I use Nuget.
    – Ben Mills
    Feb 21, 2012 at 15:57
  • 3
    The structure is awkward for a bunch of reasons. I like your structure best, but even if I give in and use Scripts, I need a subfolder for all of my code to keep it clean and separated. Libraries should be the subfolder, not my stuff. Apr 11, 2013 at 1:51

4 Answers 4

13

A workaround is to use the Nuget Package Explorer and download the package you want into that. You can then edit the folders within the package using Package Explorer to suit your taste and save it into your own Nuget repository. This can be a file system folder or you can get more sophisticated here: Hosting Your Own NuGet Feeds.

Of course this means that you have to keep the packages in your private repository up to date. Clearly if you have a lot of packages to deal with this could become a problem. However it seems quite likely that a future release of Nuget will deal with the issue of local feeds because it's an issue for companies that 'restrict which third-party libraries their developers may use' as mentioned in the Hosting your own NuGet feeds reference above.

6

I believe the answer to that is "No." There are, however, some references to be able to set the root folder NuGet installs things into: http://nuget.codeplex.com/workitem/215 (see the comments)

2
  • 4
    I believe that work item is related to where the /packages folder is located, not where the content files from a project are installed to. Anyway, you are correct that NuGet does not currently support this. Content files are installed relative to the root of the project. I agree that it would be nice to define paths for common file types. Perhaps you should add a work item on CodePlex.
    – Kiliman
    Jun 23, 2011 at 22:30
  • Do you happen to know if that is still the case? You answered this quite some time ago, so I was wondering if something was put in place to allow such functionality.
    – julealgon
    Jan 2, 2017 at 15:02
3

How jQuery gets installed is determined by the package producer, which is the jQuery team in your case. Where the jQuery package gets installed is up to you.

However, the where can only be adjusted in terms of the location of the installed package ($(SolutionDir)\packages folder is the default), and the target project where you install it into. From then on, the package producer takes over and decides where each piece of the package content ends up.

There are some good conventions for ASP.NET MVC, such as a Content folder, a Scripts folder, an App_Start folder (for WebActivator), etc. Think about the risks and extra effort involved of trying to move away from these conventions. Do they outweigh the benefits?

Now if you really want to use your own conventions, you could create your own package with your desired content structure and put the jQuery scripts where you want them in the consuming projects.

This means you would be using your own package with that specific version of jQuery. You just have to be careful to respect the licensing policy of the original package, and not to break any specific installation steps or requirements from the original package, which is fairly easy to do if you manually start changing package structure.

0

The answer to this is "no" because the "Content" folder is one of the Nuget's convention folders. However, if you rename your Content folder to, for instance, public and then have Nuget pack your public/js folder then when you bring the package in it will extract the files to the public/js folder.

Since I started to use Nuget I switched to using public for my public content instead of Content and rather use Content for files that I want to bring in untouched like source files (see here one usage of Content).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.