Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6470339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:05:58+00:00 2026-05-25T06:05:58+00:00

Note: I’m using Mercurial as an example here, because that’s what I’m trying to

  • 0

Note: I’m using Mercurial as an example here, because that’s what I’m trying to get to work with MSBuild right now.
But the problem is not limited to Mercurial, it happens with every external program that is somewhere in my %PATH% variable (I tried the same with PowerShell, for example).
So I didn’t put the Mercurial tag on this question on purpose, because this is not about Mercurial!

What I actually want to do:
I want my build script to get the current revision number from my Mercurial repository and store it in a file.
The simplest way to do this from the command line is:

hg id -i >rev.txt

Mercurial is installed on my machine and the installation folder is in my %PATH% variable.
So I can run this line from anywhere on my machine (directly from the command line, or from a batch file), and it just works.

The problem occurs when I try to run this line from my build script.
I change the BeforeBuild (or AfterBuild) section of my .csproj file as follows:

<Target Name="AfterBuild">
     <Exec Command="hg id -i >rev.txt"/>
</Target>

When I compile my solution with Visual Studio, it works and the rev.txt file is created in the folder where my .csproj is.

But when I compile the exact same solution from the command line with MSBuild, the build fails with the following error message:

The command “hg id -i >rev.txt” exited with code 9009.

I googled “msbuild code 9009” and found some solutions, but all of them propose to provide the full path to the executable.
When I do this, the build succeeds with MSBuild as well.
But this is not an acceptable solution for me, because I can’t be sure that everyone using my project (including the build server) has installed Mercurial in the exact same folder.
That’s exactly what %PATH% is for…

The same happens when I put the <Exec Command="... line directly into the build script.
If I specify the path to the executable, it works.
If I don’t specify the path, it doesn’t.

Is there any trick to make MSBuild execute programs in my %PATH% variable without specifying the complete folder?


EDIT:

@leppie:

Output redirection:
You mean the fact that I save the output of my command in a text file inside the command , instead of just running hg id -i as a command and using an output parameter or something like that to get the output?
Doesn’t make any difference…the error is the same when I omit >rev.txt.

Command line args:
No, it throws the same error, even if I shorten the command to just hg (without any parameters).

Don’t forget: if I run the exact same Exec command in the exact same .csproj file from Visual Studio, or if I just provide the path to the .exe file in the command, everything works.
So IMO output redirection and command line args can’t be the problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:05:58+00:00Added an answer on May 25, 2026 at 6:05 am

    Okay, I found the solution.
    I have to admit, it was a classic case of PEBKAC 🙂

    I’ll explain it anyway, maybe it will help someone who made the same mistake:

    Basically everything I have tried (plus what James Woolfenden suggested in his answer) would have been worked…if only the batch file that I use to run the build script wouldn’t have looked like this:

    path="%windir%\Microsoft.net\Framework\v4.0.30319"
    
    msbuild build.proj
    

    Yes, exactly.
    I’m editing the %PATH% variable for the duration of this batch file, and I’m overwriting it with the path to MSBuild instead of just appending it.

    So when my build script tries to call Mercurial, it can’t find it anymore because its location is not in the %PATH% variable anymore.
    No idea why I didn’t see this before.

    The correct way would be to append the MSBuild path, leaving the other paths intact:

    path=%path%;%windir%\Microsoft.net\Framework\v4.0.30319
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note that I'm mirroring the example given here very closely. In fact, my situation
Note: Full working example now below. Original question follows: I'm having problems using ld's
Note: I’m going to use a specific object as an example here, but please
Note that I am not asking which to choose (MVC or MVP), but rather
Note: I am not sure if this is better here, or at superuser, but
NOTE: I thought I was using bash, but /bin/sh is linked to /bin/dash, which
(Note: the data here is a made up example since I can't post the
Note: I've only been using Objective-C for a week. Here's my end goal: I
NOTE: I am not set on using VI, it is just the first thing
Note: I will not be using salts. Thanks for your advice though! I'm testing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.