Include msbuild files in NuGet package?

Sep 6, 2012 at 8:41 AM

This is an entirely selfish request, but would it be feasible to include the msbuild-related files in the nuget package?

I use AjaxMin.tasks and AjaxMinTask.dll in my projects in addition to AjaxMinLibrary.dll, and like to stay up-to-date with the latest versions. Unfortunately at present that means downloading the msi, installing it, copying the files from within ProgramFiles, then uninstalling again.

It'd be great if I could simply nuget all the files I need.

Cheers,

Matt Sharpe

Coordinator
Sep 6, 2012 at 3:59 PM

I'd love to. So, question for you: how do you use it? Do you have an MSBuild task set up and call it during your build, or do you actually reference it in your project? If you reference it in your project, it would need to be in the libs folder, but if you just want to reference it in your build scripts, the tools folder would be the best bet. I'm pretty sure that's where I should put it, but I just want to ask before I do it, given my recent nuget issues.

Sep 6, 2012 at 4:17 PM

Hey, thanks for replying so soon.

I reference the .tasks file from my web application project's csproj MSBuild file, i.e. <Import Project... />.

I keep dependencies in a separate folder, and only use nuget to actually download the files before moving them to a custom location, so I don't personally mind where you locate the files. Go for wherever would suit the majority of average nuget users.

Coordinator
Sep 6, 2012 at 4:58 PM

Cool. Then I'll be sure to include the AjaxMinTask.dll and the associate MSBuild scripts in the tools folder of the very next package.

You could then reference it in your msbuild targets as $(SolutionDir)/packages/AjaxMin*/tools/AjaxMinTask.dll -- unfortunately I don't think you can use the wildcard asterisk in that path; you'd have to update your build script with the right version every time. But what I can do is also add a couple powershell scripts to the package that will add/remove an <Import> element to your project for the AjaxMin.tasks file. The <Import> will have the right path to the tools folder, and the .tasks file itself has a relative path to the dll. That would add the AjaxMin build task to your project. The script probably won't help you much, since you copy the files anyway, right?

Coordinator
Sep 8, 2012 at 5:43 AM

Release 4.66 now has the task dll in the nuget package. 

Sep 10, 2012 at 9:04 AM

That's perfect, thank you very much!

Matt

Sep 10, 2012 at 1:10 PM

I guess AjaxMin.tasks file should reside under some version-independent folder.

We are using "NuGet Package Restore" feature. My project references AjaxMin.tasks v4.66 via Import. Everyone have the same version of AjaxMin package installed; so far so good.

Now if I update AjaxMin to newer version package installation folder will change. If I checkin the project and fellow developer will get latest version the project won't load on his machine as it refers to the folder that does not exist. The only chance to fix load problem for him is to update package manually via nuget console. I would rather prefer to let NuGet to update package for him at build step via package restore, but in order to do this the project should be loadable. AFAIK installing .tasks file under version-independent folder should solve the problem.

Coordinator
Sep 10, 2012 at 4:47 PM

Hmmm... you're right. So a project points to 4.66. One developer updates to 4.67, checks in the changes. The project file now points to the tasks file under the 4.67 folder. The next developer syncs, which pulls down the project pointing to 4.67. But because the project uses the restore feature, there is no 4.67 on that second developer's machine yet, so the project fails to load because of a missing import. Bogus.

Maybe the install.ps1 script for the package is going to need to copy the AjaxMin.tasks file into the project's root folder and update the project file to point to that file. Sound about right? The copied AjaxMin.tasks file is going to have to be updated, though, to point to the right AjaxMinTasks.dll in the right package folder for the right framework version, though. Either that, or I'll have to copy the DLL as well. Okay, I'll start working on this. Doesn't seem like a simple fix, though -- I'll try to get it fixed for 4.67, but even if I do, it sounds like the upgrade to 4.67 will still have a little manual-update pain.

Jun 21, 2013 at 8:50 AM
BTW, NuGet 2.5 adds first-class support for installing .targets files - worth checking, I think.
Coordinator
Jun 26, 2013 at 6:15 PM
Excellent! I'll update the project so that it automatically adds the manifest target -- files with the extension ".ajaxmin" will be automatically built as manifests when a project adds the AjaxMin NuGet package in builds 4.96 or higher.