2

I need to run the mt.exe (part of visual studio express) to embed an application manifest into another executable. Usually the mt.exe is called from a Visual Studio command promtp. The procedure is described here.

I need to trigger this command from a PowerShell command prompt, because I want to do this during a vagrant provisioning. How can I achieve this?

2
  • Just use the full path to mt.exe if it is not recognised by PowerShell.
    – DavidPostill
    Commented Feb 27, 2017 at 12:50
  • when you're in the correct location: .\mt -manifest patch.exe.manifest -outputresource:patch.exe;1
    – SimonS
    Commented Feb 27, 2017 at 13:04

1 Answer 1

0

You can import the environment variables from Visual Studio's batch script using the Invoke-CmdScript function from this article:

Take Charge of Environment Variables in PowerShell

The function's definition is as follows:

# Invokes a Cmd.exe shell script and updates the environment.
function Invoke-CmdScript {
  param(
    [String] $scriptName
  )
  $cmdLine = """$scriptName"" $args & set"
  & $Env:SystemRoot\system32\cmd.exe /c $cmdLine |
  Select-String '^([^=]*)=(.*)$' | ForEach-Object {
    $varName = $_.Matches[0].Groups[1].Value
    $varValue = $_.Matches[0].Groups[2].Value
    Set-Item Env:$varName $varValue
  }
}

Put this function in your PowerShell profile and you can use it to run the Visual Studio script that sets the needed environment variables.

The article also contains Get-Environment and Restore-Environment functions if you want to implement scope for the environment variables the Visual Studio script sets.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .