Change working directory of msbuild.exe

I ran across this while looking for a solution to my problem. Here's my solution (build script):

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Default">
    <Exec Command="build.bat" WorkingDirectory="..\[your dir]\" />
  </Target>
</Project>

I believe that's more what you were originally looking for?

My problem was that my batch file called another that it expected to be in the same directory, but since my ms build script was being run elsewhere, the batch file failed to find the second batch file.


@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>  

Tags:

Msbuild