PowerShell 依赖管理
场景
我的 PowerShell 文件夹包含实用程序脚本库。我通过 GitHub 在我的工作计算机和家庭计算机之间共享它并进行版本控制。在工作中,我现在有许多项目想要利用我的脚本库。
问题
当我更新实用程序脚本时,我不想将其手动复制到使用它的所有工作项目中。
可能的解决方案
(简单)
编写一个 PowerShell 函数,将整个脚本库复制到每个脚本项目工作目录下的“Dependencies\Scripts”目录中。随着我的脚本库的增长,其他人可能会很难找到与脚本项目相关的库脚本。
(过于复杂?)
在需要库脚本之一的每个工作项目脚本文件中使用某种“需要”函数。当库脚本更新时,工具可以决定哪些工作项目需要该库脚本并将最新版本复制到工作项目。如果脚本在没有适当依赖项的情况下运行,它将抛出一个错误,提醒用户如何从库中获取最新版本。
问题
- 以前有人解决过这个问题吗?
- 是否有现有的 PowerShell 依赖管理工具可以执行 2 操作?
Scenario
My PowerShell folder contains a library of utility scripts. I have it shared and version controlled with GitHub between my work and home computers. At work I now have a number of projects where I want to take advantage of my script library.
Problem
When I update the a utility script, I don't want to copy it manually to all the work projects where it is used.
Possible solutions
(Simple)
Write a PowerShell function to copy my whole script library to a 'Dependencies\Scripts' directory under the working directory for each script project. As my script library grows, it may become difficult for others to find the library scripts that are relevant to the script project.
(Overcomplicated?)
Use some kind of 'requires' function in each work project script file that requires one of library scripts. When a library script is updated a tool can then decide which work projects require that library script and copy the latest version to the work project. If a script is run without the appropriate dependency it will throw an error that 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 do 2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否考虑过 NuGet?它支持包依赖项、更新和私有存储库。
另请参阅:使用 Nuget 在企业中共享 PowerShell 模块
Have you considered NuGet? It supports package dependencies, updates, and private repositories.
See also: Use Nuget to Share PowerShell Modules in your Enterprise
我为您创建了一个我认为适合您情况的解决方案。我根据歌曲播放列表方法创建了它。我创建了一个 xml 文档,您可以在其中单独列出每个脚本,并在同一文档的另一个节点中列出要为每个项目复制的脚本。我在下面创建了一个工作示例。虽然在管理数百个脚本文件或大量项目时它并不优雅,但它可以完成工作。
PS1 脚本
XML 文件
I created a solution for you that I think will fit your situation. I created it based off of the song playlist methodology. I created an xml document where you would list each of your scripts individually and in another node in the same document you list the scripts you want to copy for each project. I have created a working example of this below. Though it is not elegant when it comes to managing a few hundred script files or alot of projects but it gets the job done.
PS1 Script
XMLFile
一个简单的解决方案是使用 DropBox 之类的东西。您可以在此处查看我如何将其用于 PowerShell 脚本: http://www.ravichaganti.com /blog/?p=1963
您可以获得一个拥有 2GB 可用空间的 DropBox 帐户 http://db.tt /1DID1mR。在我看来,2GB 对于简单的脚本来说已经足够了。市场上还有其他选择。不过,我推荐 DropBox。免费帐户支持恢复 30 天前的文件版本。
A simple solution would be to use something like DropBox. You can see how I use it for my PowerShell Scripts here: http://www.ravichaganti.com/blog/?p=1963
You can get a DropBox account with 2GB of free space http://db.tt/1DID1mR. 2GB, in my opinion, is more than enough for simple scripts. There are also other choices in the market. However, I recommend DropBox. The free account supports restoring 30 days old file versions.