Question

Can the Albacore nuspec task resolve all needed dependencies for a solution? When I have several projects with changing dependencies it takes a lot of effort to keep the rakefile up to date. Can this be automated?

desc 'create the nuget package'
nuspec do |nuspec|
   nuspec.id = 'myprojectid'
   nuspec.version = '1.2.3'
   nuspec.authors = 'Jon Jones'
   nuspec.description = 'my-project is a collection of utilties'
   nuspec.title = 'my-project'
   nuspec.dependency <magic here>
end

A manual solution would be to go through the packages files and resolve this by hand. Has anyone written up anything automated?

Was it helpful?

Solution

I realize this is an old question, but seeing as it doesn't have an answer, this might help someone looking for the same thing. I'm currently working on some Rake Tasks to further automate the creation of nuspec files in a conventional/autonomous way, so I'll update this post later with the final solution.

To answer the question at hand though, here's a little ruby function that will pull dependencies out of the packages.config file for a given project in the solution.

def GetProjectDependencies(project)
    path = "#{File::dirname project.FilePath}/packages.config"
    packageDep = Array.new

    if File.exists? path
        packageConfigXml = File.read("#{File::dirname project.FilePath}/packages.config")
        doc = REXML::Document.new(packageConfigXml)
        doc.elements.each("packages/package") do |package|
            dep = Dependency.new
            dep.Name = package.attributes["id"]
            dep.Version = package.attributes["version"]
            packageDep << dep
        end
    end

    packageDep
end

And the Dependency class used:

class Dependency
    attr_accessor :Name, :Version

    def new(name, version)
        @Name = name
        @Version = version
    end
end

This method takes in a "project" instance, and grabs the dependency/versions from the package.config file for that project.

As I said, I'll post a more complete solution soon, but this is a good starting point for anyone if they need it.

EDIT: Sorry it took me so long to post the final version of this, but here's a link to the gist containing the sample code I'm currently using for a number of projects.

https://gist.github.com/4151627

Basically, I wrap the data in a "Project" class, and populate dependencies from package.config. As a bonus, it also adds dependencies from interproject references (parses the project file). The classes/logic is there, as well as a sample nuspec task.

OTHER TIPS

To be sure, there's nothing in the Albacore project that does that right now. It would be interesting to see Mitchell's solution tuned up and maybe rolled in. I'm going to move the code to a gist, open an "issue" (enhancement), and work on it on the side :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top