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?
source to share
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.
source to share