0

I want to execute the power shell logic using c#(web application) but i'm getting the issue

The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I have added the git path in environmental variables and able to execute the same powershell logic from powershell window without any issues.

My powershell script:

function CheckoutTheCode($checkoutRepoUrl, $checkoutDirectory, $checkoutBranch)
{
    [hashtable]$Return = @{}
    try
    {
        # Cloning
        git clone --single-branch -b $checkoutBranch $checkoutRepoUrl $checkoutDirectory

        $Return.Status = $true
        $Return.Message = "Success"
    }
    catch
    {
        $Return.Message = $Error[0].Exception
        $Return.Status = $false
    }

    Return $Return 
}

$checkoutDirectory = "local directory for checkout"
$checkoutRepoUrl = "bit bucket repo url"
$checkoutBranch = "branch version"
CheckoutTheCode $checkoutRepoUrl $checkoutDirectory $checkoutBranch

My c# code:

using (PowerShell PowerShellInstance = PowerShell.Create())
{
    PowerShellInstance.AddScript("PowerShell script");
    Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
}
8
  • To clarify: you added a system environment variable, right? And the user the web app runs as has access to the folder git resides in, right? Commented Oct 5, 2018 at 6:49
  • Yes, I have added system environment variable. Yes the user with which the app runs have access to the folder in which git resides in. Commented Oct 5, 2018 at 6:53
  • You are correct, but you also need to check if the user IIS / IIS Express is running under has access to that folder. Commented Oct 5, 2018 at 6:53
  • Sorry at first i have misunderstood your confirmation question. Yes, I have added system environment variable. Yes the user with which the app runs have access to the folder in which git resides in. Commented Oct 5, 2018 at 6:56
  • And you've rebooted since you added the environment variable? (I assume you have, since it works for you when you run it manually, but to cover all bases I ask...) Commented Oct 5, 2018 at 6:56

1 Answer 1

1

In My case the issue is I have added the system environment variable after the c# web application is opened in visual studio.

When i have closed the visual studio and opened again, it's working fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Typical Visual Studio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.