Search code examples
visual-studionugetrakerake-taskbuild-server

Get dynamic folder from nuget package


We use rake to build and test on our dev machines. We recently moved one of our projects to our own local NuGet server. We used to use this project as a submodule and thus it had a constant path to some of the content (license files, libraries for deployment, etc). I've been playing around with how the NuGet package is created and I thought that I had it figured out by putting that content as "content" in the NuGet package. Problem is that NuGet only puts those files on install, and I won't include things that get added by NuGet. So when I push my code up and use our build server it fails because the required content files never get restored. So my thought was to put those files into the /package/ourproject.2016.10.20.16 folder. The pain point I see that is if someone updates the NuGet package in the project they'll also have to update the rakefile. To point at the new tools folder. Thankfully NuGet automagically names the project by the package name and version number so it is consitant in that regard. We use the build date and build number as the version yyyy.mm.dd.bb.

this is the portion of the rake file in interest

task :copy_to_deployment_folder do
    copy_hash = {
        "." => ["#{solutionName}.Deployment/Scripts/DevDeploy.bat",
                "#{solutionName}.Deployment/Scripts/QaDeploy.bat",
                "#{solutionName}.Deployment/Scripts/PreProdDeploy.bat",
                "#{solutionName}.Deployment/Scripts/ProdDeploy.bat",
                 ],
        "Applications/#{solutionName}" => "#{solutionName}/bin/{configuration}",
        "deploy" => ["#{solutionName}.Deployment/deploy_bin",
                       "#{solutionName}.Deployment/bin/{configuration}"],
        "deploy/settings" => "#{solutionName}.Deployment/settings",
        "deploy/Licenses" => "packages/ourproject.2016.10.20.20/tools/Licenses"
    }

    BuildController.copy_to_deployment_folder copy_hash
end

specifically the last element in the copy_hash would need to change each time that project was updated in NuGet. (I suppose not the worse problem, and this is the only project that references this package. but if there was a way to make it more dynamic by using wild cards or something that would be awesome. Any ideas?


Solution

  • I figured it out! it was rather simple actually. I used Dir.glob (sorry if that isn't good, but I'm not a Ruby person.

    task :copy_to_deployment_folder do
        packagePath = Dir.glob("packages/ourproject.*")[0]
        copy_hash = {
            "." => ["#{packagePath}/content/Scripts/DevDeploy.bat",
                    "#{packagePath}/content/Scripts/QaDeploy.bat",
                    "#{packagePath}/content/Scripts/PreProdDeploy.bat",
                    "#{packagePath}/content/Scripts/ProdDeploy.bat",
                     ],
            "Applications/#{solutionName}" => "#{solutionName}/bin/{configuration}",
            "deploy" => ["#{packagePath}/content/deploy_bin",
                           "#{solutionName}.Deployment/bin/{configuration}"],
            "deploy/settings" => "#{solutionName}.Deployment/settings",
            "deploy/Licenses" => "#{packagePath}/content/Licenses"
        }
    
        BuildController.copy_to_deployment_folder copy_hash
    end