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 6652119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:05:47+00:00 2026-05-26T01:05:47+00:00

I am executing MSBuild from a batch file. The MSBuild script is in a

  • 0

I am executing MSBuild from a batch file. The MSBuild script is in a different directory than the directory I want MSBuild to consider the working directory when running the script. When invoking MSBuild.exe, how do I change its working directory?

Edit: More details
Let’s say I have an MSBuild script located on some other server. I want to run a command thusly:

msbuild.exe \\my_server\c$\My\Path\To\Scripts\TestScript.msbuild

I run that command with my command prompt at c:\temp. Let’s say my TestScript.msbuild has a task to create a file. The file has no path just a filename. I would expect that the file gets created inside c:\temp. But it doesn’t it gets created next to the msbuild file that is sitting on the server. This is the behavior I want to change.

Edit #2
Here is the script I’m using in my test:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   
    <ItemGroup>
        <Files Include="HelloWorld.txt" />
    </ItemGroup>

    <Target Name="TouchFiles">
        <Touch Files="@(Files)" AlwaysCreate="True" />
    </Target>
</Project>

I am going into a command shell CDing into c:\temp and then executing the script. With or without the /p:OutDir switch that @Nick Nieslanik mentions, the HelloWorld.txt file appears in the folder where the *.msbuild file is and not c:\temp.

  • 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-26T01:05:48+00:00Added an answer on May 26, 2026 at 1:05 am

    @jkohlhepp – I see now. You are doing the opposite of what I described in my comment to some degree.

    MSBuild common targets use the MSBuildProjectDirectory to determine the output folder unless you override that. So in your case, you could run

    msbuild.exe \\my_server\c$\My\Pat\To\Scripts\TestScript.msbuild /p:OutDir=c:\temp 
    

    to force the output to be dropped in that location.

    EDIT:
    Given the project file above, you’d need to edit it to do something like the following for this to work:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <OutDir Condition=" '$(OutDir)' == '' ">bin\debug\</OutDir>
      </PropertyGroup>
      <ItemGroup>  
        <!-- Without prefacing files with paths, they are assumed relative to the proj file -->
        <FilesToCreate Include="$(OutDir)HelloWorld.txt" />  
      </ItemGroup>  
      <Target Name="TouchFiles">  
         <Touch Files="@(FilesToCreate)" AlwaysCreate="True" />  
      </Target>  
    </Project>  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i am using batch file for invoking msbuild.exe ,logging functionality works fine. But
How can I automate executing a batch file from TeamCity. Can I create a
I have a MSBuild script that I am executing through TeamCity. One of the
I have a build script (.bat) that invokes MSBUILD ( C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe ) that used
Quick question about MSBuild. I have the following MSBuild file in directory d:\MyDirectory <Project
Aim to Acheive : I want to execute my application from msbuild as it
When executing :make from vim, after make is complete it automatically jumps to a
Aside from executing XP_CmdShell, which I have disabled in my SQL 2005 installation, what
while executing a long script that uses Doctrine to access the db, I get
Executing SP to check who is currently logon in the SQL working fine in

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.