【问题标题】:Powershell 7: How to read from a file and add dotnet packagesPowershell 7:如何从文件中读取并添加 dotnet 包
【发布时间】:2021-05-03 00:13:31
【问题描述】:

我是 Powershell 7 的新手

我有一个格式如下的 .txt 日志文件:

Include Version
Microsoft.ApplicationInsights 2.17.0
NewtonSoft.Json 13.0.1

我需要迭代并读取该文件的包名称和版本,并以某种方式将值插入到如下内容中:

dotnet 包添加 {packagename} --version {version}

任何关于最佳方法的指导将不胜感激。

谢谢。

【问题讨论】:

    标签: .net .net-core powershell-core powershell-7.0 dotnetcorecli


    【解决方案1】:

    不久前,我写了一个 cmdlet ConvertFrom-SourceTable,它可以读取很多(对齐的)数据表,包括来自 StackOverflow 的数据表,请参阅 New Feature: Table Support

    $Table = '
    |Include                       |Version|
    |------------------------------|-------|
    |Microsoft.ApplicationInsights |2.17.0 |
    |NewtonSoft.Json               |13.0.1 |'
    
    $Table | ConvertFrom-SourceTable
    
    Include                       Version
    -------                       -------
    Microsoft.ApplicationInsights 2.17.0
    NewtonSoft.Json               13.0.1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-10
      • 1970-01-01
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 2023-01-26
      相关资源
      最近更新 更多