none
Deployment of Nuget package files RRS feed

  • Question

  • I have a Unit Test project that depends on files that are located in a Nuget Package that the test uses.  I need to copy certain files from the Nuget packages folder to the test run folder.  Currently I have been using a .testsettings file with DeploymentItem elements that copy files from the packages folder.  This works fine except for one problem.... The Nuget packages folder contains sub-folders for each package that have the version number of the Nuget Package as a part of the sub-folder.  When I update my Nuget package to a newer version, the package sub-folder name changes to reflect the new version of the package.  This causes me to have to go in to the .testsettings file and update all of the DeploymentItems to use the new folder version name.

    Is there any way that I can deploy files from the Nuget packages folder without the version number of the package being a factor on the folder name?  Or, is there a way that I can configure Nuget so that it doesn't include the version number in the sub-folder for each package? Keep in mind that I do not have control over the generation of the Nuget packages themselves. I need this to work on the package consumption side.

    Monday, October 26, 2015 4:31 PM

Answers

  • I came up with a work-around for this problem. I created a post-build batch script to copy the Nuget packages folder into another folder with the version numbers removed.  I call the batch script as part of the post build step for the project. I used the following 'for' cmd to do this in the batch script:

    for /D %%f in ("%~1myPackage*") do xcopy "%%f" "%~2myPackage" /s /i /y

    where myPackage is the name of the package folder containing the version.

    I repeat that same 'for' statement on every package folder with the asterisk appearing just before the package version.

    For the %1 and %2 script arguments, I pass in "$(SolutionDir)packages\" for %1 and "$(SolutionDir)packages\deploy\" for %2

    This allows me to use a DeploymentItem in the .testsettings file that doesn't need to be changed for each new version of the Nuget package that is downloaded.



    • Marked as answer by Ken Varn Tuesday, November 3, 2015 2:15 PM
    • Edited by Ken Varn Tuesday, November 3, 2015 2:16 PM
    Tuesday, November 3, 2015 2:14 PM

All replies

  • Hi Ken,

    >>Is there any way that I can deploy files from the Nuget packages folder without the version number of the package being a factor on the folder name? 

    You know that we could use the deploymentitem option for the files directly or the folder of the files.

    But as you said that if the Nuget package folder name has been changed when you update the package, I think it would not find the folder/files in your previous deployment settings.

    >> Or, is there a way that I can configure Nuget so that it doesn't include the version number in the sub-folder for each package?

    The real reason is that we just download and install it from the Manage NuGet package, it is hard for us to control the folder name with the version number in our side. So it would have a limitation for this issue. 

    So we would change the settings manually for the deployment files.

    Or you could submit this feature request: http://visualstudio.uservoice.com/forums/121579-visual-studio.
    The Visual Studio product team is listening to user voice there.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 28, 2015 2:20 AM
    Moderator
  • I came up with a work-around for this problem. I created a post-build batch script to copy the Nuget packages folder into another folder with the version numbers removed.  I call the batch script as part of the post build step for the project. I used the following 'for' cmd to do this in the batch script:

    for /D %%f in ("%~1myPackage*") do xcopy "%%f" "%~2myPackage" /s /i /y

    where myPackage is the name of the package folder containing the version.

    I repeat that same 'for' statement on every package folder with the asterisk appearing just before the package version.

    For the %1 and %2 script arguments, I pass in "$(SolutionDir)packages\" for %1 and "$(SolutionDir)packages\deploy\" for %2

    This allows me to use a DeploymentItem in the .testsettings file that doesn't need to be changed for each new version of the Nuget package that is downloaded.



    • Marked as answer by Ken Varn Tuesday, November 3, 2015 2:15 PM
    • Edited by Ken Varn Tuesday, November 3, 2015 2:16 PM
    Tuesday, November 3, 2015 2:14 PM