Can the Albacore nuspec task resolve all dependencies automatically?

Can the Albacore nuspec task resolve all required dependencies for a solution? When I have multiple projects with changing dependencies, it takes a lot of effort to update the rakefile. Could 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 package files and solve it manually. Has anyone written anything automated?

+3


source to share


2 answers


I realize this is an old question, but seeing that it has no answer, it might help someone looking for the same thing. I am currently working on some Rake tasks to further automate the generation of nuspec files in the normal / offline way, so I will update this post later with the final solution.

To answer the question though, here's a little ruby โ€‹โ€‹function that pulls dependencies from the packages.config file for a given project in a 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 is used:

class Dependency
    attr_accessor :Name, :Version

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

      



This method takes an instance of "project" and grabs the dependencies / versions from the package.config file for that project.

As I said, I will post a more complete solution shortly, but this is a good starting point for everyone 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 several projects.

https://gist.github.com/4151627

Basically, I wrap the data in the Project class and populate the dependencies on the package.config. As a bonus, it also adds dependencies on links between projects (parses the project file). There are classes / logic as well as an example nuspec task.

+3


source


Of course, there is nothing in the Albacore project that is doing it right now. It would be interesting to see that Mitchell's solution is configured and possibly reversed. I'm going to move the code into the gist , open an " issue " and work on it from the side :)



+1


source







All Articles