none
Does NGEN set an error code environment variable RRS feed

  • Question

  • Hi All,

    Does ngen.exe set an environment variable with it's return code (success=0, failure=?? (I've seen 0xffffffff))?  I need this execution status returned to my installation script just in case it fails, I need to rollback my installation.

    Thanks, WordRake

    Friday, August 2, 2013 12:18 AM

Answers

  • It only returns 0 or -1, never other values.

    You can use the PowerShell script above, pipe it to where { $_ -match "expression"} to try to get the HRESULT. (I'm no expert in RegEx so you may seek help from the others and see if they can get it better.)

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe a | ? { $_ -match "0x[\dA-F]{8}" } | select -first 1 | % { $_ -replace ".*0x[\dA-F]{8}.*", $1; $matches[0] }


    • Edited by cheong00Editor Thursday, August 8, 2013 8:04 AM
    • Marked as answer by WordRake Friday, August 9, 2013 4:43 PM
    Thursday, August 8, 2013 8:02 AM
    Answerer

All replies

  • Hello,

    Welcome to MSDN forum.

    According to your  description ,I know that you set an environment variable in Ngen.exe , it appear a error, right? i don't know which environment variable are set, what is indicate error  ?

    To help you further, could you describe error inmforamtion in detail?  Thanks .

    Best Regards,


    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 2, 2013 7:42 AM
    Moderator
  • Sorry, maybe I wasn't clear.  My question is whether ngen.exe (when run in a script) sets an environment variable with its "return code".  I.E. if ngen is successfull, it returns zero say, and if it experiences a failure, it returns an error code.  Other applications set %errorlevel%.  Does ngen.exe expose it's "return code" that is accessible to a script?

    Thanks, WordRake

    Friday, August 2, 2013 4:55 PM
  • Hello,

    Welcome to MSDN forum,

    From your description, I think that it’s impossibility,  now there is no such kind of exposed value.  I will try to see if there is any other way to communicate with ngen.exe.

    Have a nice day.


    Best Regards,
    Lilia Gong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 7, 2013 6:56 AM
    Moderator
  • All,

    So I have been successful using PowerShell.  Maybe it will translate into basic script as well.

    WordRake

    # Attached PowerShell Script Start:
    $LastExitCode = 3
    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install "c:/program files/<my company>/<my product>/<my addin>.dll"
    if($LastExitCode -ne 0)
    {
        Write-Host "Ngen Failed: " + $LastExitCode           # I've seen failure value = -1
    }
    else
    {
        Write-Host "Ngen Successfull: " + $LastExitCode    # Usually value = 0
    }

    Wednesday, August 7, 2013 8:53 PM
  • It only returns 0 or -1, never other values.

    You can use the PowerShell script above, pipe it to where { $_ -match "expression"} to try to get the HRESULT. (I'm no expert in RegEx so you may seek help from the others and see if they can get it better.)

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\ngen.exe a | ? { $_ -match "0x[\dA-F]{8}" } | select -first 1 | % { $_ -replace ".*0x[\dA-F]{8}.*", $1; $matches[0] }


    • Edited by cheong00Editor Thursday, August 8, 2013 8:04 AM
    • Marked as answer by WordRake Friday, August 9, 2013 4:43 PM
    Thursday, August 8, 2013 8:02 AM
    Answerer