0

I have a Powershell script that reads the Assembly version from a dll, I want to store this return value in a variable, I am running the ps1 script from a post-build event:

When i execute the script:

powershell -NoProfile -ExecutionPolicy RemoteSigned -file $(SolutionDir)GetAssemblyVersion.ps1 $(TargetPath)

The post build event produces this:

1>1.0.8146.38525

I want to assign this value to a variable to be able to use it later in another operation, unfortunately, it has not worked

A=(powershell -NoProfile -ExecutionPolicy RemoteSigned -file $(SolutionDir)GetAssemblyVersion.ps1 $(TargetPath))

I have also tried this:

A=$(powershell -NoProfile -ExecutionPolicy RemoteSigned -file $(SolutionDir)GetAssemblyVersion.ps1 $(TargetPath))

None of these two solutions is working.

My Powershell script is the following one:

$strPath = $args[0]
$Assembly = [Reflection.Assembly]::Loadfile($strPath)
$AssemblyName = $Assembly.GetName()
$Assemblyversion = $AssemblyName.version
$Assemblyversion.ToString()

I appreciate your comments and suggestions

Benny _
  • 9
  • 1
DonMiguelSanchez
  • 376
  • 3
  • 15
  • https://social.msdn.microsoft.com/Forums/en-US/f3edc876-44e0-4bcc-8dd2-95bddd115849/how-to-save-cmd-output-into-a-variable?forum=csharpgeneral might be useful – Robert Cotterman Apr 22 '22 at 02:03
  • The proper way would be to just write the function into c# as you're REALLY slowing down performance by calling another process. THIS might help ---> https://stackoverflow.com/questions/1755504/programmatically-get-the-version-number-of-a-dll – Robert Cotterman Apr 22 '22 at 02:04

0 Answers0