Update NuGet MVC packages and pre-processed files - asp.net-mvc

Related to: Package an ASP.NET MVC application with Nuget
I'm trying to get a mode where I can edit an MVC project and package it easily.
As often suggested it is wise to replace a namespace using NuGet pre-processor functionality.
This would mean that I would have to edit my source files and add the pp extensions to each pre-processed source file.
Are there any tips and tricks to make this less labourious?

There is such a tool, that did almost exactly what I wanted. It's on Codeplex so I could participate in the development, yay!
https://nugetpackager.codeplex.com/
It has a common-line interface too, so I can script my updates.

Related

Is it safe to exclude Scaffolding packages from publish version?

I have Microsoft.VisualStudio.Web.CodeGeneration.Design nuget in a project.
Can it be safely excluded from publishing (<ExcludeAssets>runtime</ExcludeAssets>)?
Is there scenario, when during runtime, code has dependency on this package?
As I understand this package is used only for generating the code during development.
I don't see any reason to add its dll in published code.
Is it safe to exclude Scaffolding packages from publish version?
As the package describes,
Code Generation tool for ASP.NET Core. Contains the
dotnet-aspnet-codegenerator command used for generating controllers
and views.
It only works for generating code for views or controllers during developing and the project itself does not depend on the package at runtime.
So it is safe to exclude that nuget package from publishing using your method. And you do not have to worry too much about it.

Nuget package the depends on 1 of N Nuget packages?

I am working on an open source project MvcSiteMapProvider getting it ready for deployment. It is a library package that supports MVC2, MVC3, and MVC4 as well as .NET 3.5, .NET 4.0, and .NET 4.5.
Based on Nuget Package: Use Different MVC Version When Available, I have come to the conclusion that I need to make a Nuget package for each version of MVC and let Nuget's internal version detection take care of the different .NET versions, like this:
MvcSiteMapProvider.MVC2
MvcSiteMapProvider.MVC3
MvcSiteMapProvider.MVC4
However, in addition to a library DLL, I have different files (Dependency Injection configuation, MVC DisplayTemplates, etc.) that need to be deployed to the target project. These files MUST NOT be updated when the new version of the main project is updated because they will likely contain end-developer edits that I don't want to overwrite.
So, it is clear that these need to be in their own Nuget packages for this and other reasons. However, these other packages need to depend on the main MvcSiteMapProvider.MVCx projects, just to ensure one of them has been installed.
It doesn't make sense to make a separate Nuget package for each version of MVC for each of these other packages - they are all exactly the same except for this one dependency. Ideally what I would like to do is make a single Nuget package that depends on either MvcSiteMapProvider.MVC2, MvcSiteMapProvider.MVC3, or MvcSiteMapProvider.MVC4 and if none of them are available, install the one that matches the MVC version of the target project, but how would I accomplish this? If that is not possible, what other options do I have than creating large number of Nuget packages (one for each MVC version dependency) that grows exponentially with each new MVC release?
To clarify, I have other Nuget packages like this:
MvcSiteMapProvider.Web
MvcSiteMapProvider.Configuration.Autofac
MvcSiteMapProvider.Configuration.Ninject
MvcSiteMapProvider.Configuration.StructureMap
MvcSiteMapProvider.Configuration.Unity
MvcSiteMapProvider.Configuration.Windsor
I am trying to avoid having to change that to:
MvcSiteMapProvider.MVC2.Web
MvcSiteMapProvider.MVC2.Configuration.Autofac
MvcSiteMapProvider.MVC2.Configuration.Ninject
MvcSiteMapProvider.MVC2.Configuration.StructureMap
MvcSiteMapProvider.MVC2.Configuration.Unity
MvcSiteMapProvider.MVC2.Configuration.Windsor
MvcSiteMapProvider.MVC3.Web
MvcSiteMapProvider.MVC3.Configuration.Autofac
MvcSiteMapProvider.MVC3.Configuration.Ninject
MvcSiteMapProvider.MVC3.Configuration.StructureMap
MvcSiteMapProvider.MVC3.Configuration.Unity
MvcSiteMapProvider.MVC3.Configuration.Windsor
MvcSiteMapProvider.MVC4.Web
MvcSiteMapProvider.MVC4.Configuration.Autofac
MvcSiteMapProvider.MVC4.Configuration.Ninject
MvcSiteMapProvider.MVC4.Configuration.StructureMap
MvcSiteMapProvider.MVC4.Configuration.Unity
MvcSiteMapProvider.MVC4.Configuration.Windsor
Looking at your source code, it seems like you are referencing multiple versions of the Microsoft.AspNet.Mvc package in MvcSiteMapProvider project. I am not sure this is working as you expect it to since there can be only one version of System.Web.Mvc that can be put in the bin folder during the compilation process (the latest version 5.0.0 will be used).
So any code in your package that depends on Mvc V3 or V4 is not really getting the dll it expects.
Since most of the packages you referenced above like Autofac also have integration package that target specific MVC versions,you may not have an option but to split your package into smaller packages like you mentioned in your post.
A better approach to this problem would be to separate the Core functionality provided by your package which does not have dependency on any version of MVC. You can then create different wrapper packages that depend on your core package and also on a specific version of Microsoft.AspNet.Mvc. And create similar packages for each different Configuration has a nuget dependency on third party packages like Autofac (eg Autofac.Mvc5) and its corresponding version of your MvcSiteMapProvider.MvcX package

direct nuget where to put files

I am working with nuget and find it excellent with my MVC4 project. I use it for all my external dependencies.
I have run in to one small problem with it. For example, installing the jQuery package, it places the jQuery files in to the Scripts folder. My preference is that it places the javascript files in to a libraries folder within scripts. So instead of
Scripts/jquery-1.8.3.js
I want to place it in
Scripts/libraries/jquery-1.8.3.js
Yes I can manually move it but then I lose the features of nuget. Any way that I can direct where a package places the files like this?
This is not supported yet
dupe of
NuGet scripts to different directory
, nuget codeplex issue is here http://nuget.codeplex.com/workitem/1914

Are Umbraco and NuGet packages interchangeable?

I'm building websites in Umbraco and they all use similar components and base templates. The obvious best practice is to create packages that install these things ready. But I can't tell how to do things like add project references in Umbraco, and I can't tell how to create document types (a database object) in NuGet.
I've not been able to find a good comparison of abilities - what one package can do that the other can't - to be able to choose one or the other types of package. Or will I have to use both types of packages for different jobs (I don't want to go down this route if I can help it, since some features may require both packages).
EDIT for clarification, hopefully this will help. I'm trying to ask a blanket question to find out whether it is possible to use only one packaging system, rather than two. I want to avoid installing 2 different packages to get something to work properly.
Can a NuGet package trigger an automatic install of an Umbraco package?
Can a NuGet package create Umbraco objects, like document types, etc?
Can an Umbraco package add assembly references to a project?
I'm not sure where you're trying to use NuGet in Umbraco, the Umbraco packaging system isn't NuGet based, it's entirely different to NuGet (caveat - the next version of Umbraco will use NuGet for packaging).
The Umbraco package system, as currently defined, is capable of deploying any file into your target project be that CSS, JavaScript, Templates, Assemblies, User Controls, etc, as well as data into your database (Document Types, Content, etc).

ASP.NET: NuGet/NuPack: Configuring location package files are put in

Okay, so help me understand something here. I've got a new MVC solution and want to use NuGet to keep Modernizr up to date.
The problem is, NuGet puts the Modernizr scripts under ~/Scripts. This won't work--we've decided to put our JS in ~/js.
How do I modify the configuration of this package to tell NuGet that the Modernizr package should go in ~/Scripts or ~/Scripts/global instead?
I don't think you can do this - I don't think this is functionality of NuGet, but rather the location of the scripts inside the NuGet package. This could vary from one package to another :-(
This is currently not a feature of NuGet, but it was mentioned in discussion on the a NuGet forums including members of the NuGet team. I don't see any work item that has officially been created for this yet, unfortunately. I performed a quick search of the NuGet issues list for the word "location" and didn't see one out there for this. You might want to request it as a feature.

Resources