Powershell 7: How to read from a file and add dotnet packages

70 views Asked by At

I am new to Powershell 7

I have a .txt log file formatted like this:

Include Version
Microsoft.ApplicationInsights 2.17.0
NewtonSoft.Json 13.0.1

I need to iterate and read the package names and versions of this file and somehow insert the values into something like this:

dotnet package add {packagename} --version {version}

Any guidance on the best approach would be greatly appreciated.

Thanks.

1

There are 1 answers

0
iRon On

A while ago, I wrote a cmdlet ConvertFrom-SourceTable that can read a lot of (aligned) data tables including the ones from StackOverflow, see 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