PowerShell Dependency Management

Scenario

My PowerShell folder contains a script library. I have shared access, and the version is controlled by GitHub between my work and home computers. At work, I now have a number of projects in which I want to use the script library.

Problem

When I update the script utility, I donโ€™t want to manually copy it to all working projects where it is used.

Possible solutions

  • (Simple)

    Write a PowerShell function to copy my entire script library to the Dependencies \ Scripts directory in the working directory for each script project. As my script library grows for others, it may be difficult to find library scripts related to the script project.

  • (complicated?)

    To use any function โ€œrequiredโ€ in each script file of the project project, which requires one of the library scripts. When the script library is updated, the tool can then decide which work projects require this script library and copy the latest version into the work project. If the script is run without the corresponding dependency, it throws an error reminding the user how to get the latest version from the library.

Questions

  • Has anyone solved this problem before?
  • Are there existing dependency management tools for PowerShell that will run 2?
+5
source share
3 answers

, , , . . XML-, , node , . . , script , .

PS1 Script

[xml]$XML = gc "C:\XMLFile1.xml"
$Scripts = $XML.Root.Scripts.Script
$Projects = $XML.Root.Projects.Project
foreach($Project in $Projects){
    $ProjectLocation = $Project.CopyPath
    $ProjectScripts = $Project.Script
    foreach($Script in $ProjectScripts){
        $ScriptPath = ($Scripts|?{$_.ID -eq $Script.ID}|Select Path).Path
        Copy-Item -Path $ScriptPath -Destination $ProjectLocation
    }
}

XMLFILE

<Root>
  <Scripts>
    <Script ID="1" Path="C:\1.PS1"></Script>
    <Script ID="2" Path="C:\2.PS1"></Script>
    <Script ID="3" Path="C:\3.PSM1"></Script>
  </Scripts>
  <Projects>
    <Project Name="Project1" CopyPath="\\Server\Share\Project1">
      <Scripts ID="1"/>
    </Project>
    <Project Name="Project2" CopyPath="C:\Projects\Project2">
      <Scripts ID="1"/>
      <Scripts ID="3"/>
    </Project>
  </Projects>
</Root>
+1
+1

- DropBox. , PowerShell : http://www.ravichaganti.com/blog/?p=1963

DropBox 2 http://db.tt/1DID1mR. 2GB, , . . DropBox. 30- .

0

All Articles