tags:

views:

81

answers:

2

This is my first dive into MSBuild so I'm feeling pretty lost.

The end goal is to run an executable which will output a file, and we want the output of the build to be that file. In this build there is no VS project what so ever.

The build is being run by TFS build services.

At this point all I'm trying to do is generate a file and have it copied to the drop folder.

Here is the contents of my .proj file

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;

 <Target Name="Build">
  <Message Text="Output Dir: $(OutDir)" />
  <MakeDir Directories="$(OutDir)" />
  <Exec Command='dir /s > \\ANetworkPath\dir.txt
    dir /s > $(OutDir)Dir2.txt'/>
 </Target>
</Project>

The first command of writing dir to the network path succeeds, however it doesn't show the existence of $(OutDir). So I thought I would try to create it with MakeDir. When the second dir command executes it errors because the path doesn't exist.

TFS is running MSBuild with the following command

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /nologo /noconsolelogger "C:\Builds\1\Scratch\Test Build\Sources\user\Test\Build.proj" /m:1 /fl /p:SkipInvalidConfigurations=true  /p:OutDir="C:\Builds\1\Scratch\Test Build\Binaries\\" /p:VCBuildOverride="C:\Builds\1\Scratch\Test Build\Sources\user\Test\Build.proj.vsprops"  /dl:WorkflowCentralLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/111;InformationNodeId=6570;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;TFSUrl=http://tfshost:8080/tfs/Test%20Collection;"*WorkflowForwardingLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;"

The only output is in the file written on the network:

Directory of C:\Builds\1\Scratch\Test Build\Sources\user\Test

09/17/2010  10:53 AM    <DIR>          .
09/17/2010  10:53 AM    <DIR>          ..
09/17/2010  10:53 AM    <DIR>          A Directory
09/17/2010  10:53 AM                 0 Test.log
09/17/2010  10:53 AM               453 Test.proj
09/17/2010  10:53 AM               201 Test.proj.vsprops
               3 File(s)            654 bytes

 Directory of C:\Builds\1\Scratch\Test Build\Sources\user\Test\A Directory

09/17/2010  10:53 AM    <DIR>          .
09/17/2010  10:53 AM    <DIR>          ..
09/17/2010  10:53 AM                 9 A File.txt
09/17/2010  10:53 AM                15 Another File.txt
               2 File(s)             24 bytes

     Total Files Listed:
               5 File(s)            678 bytes
               5 Dir(s)  40,243,372,032 bytes free

Here is the build log:

Build started 9/17/2010 12:05:29 PM.
Project "C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj" on node 1 (default targets).
Build:
  Output Dir: C:\Builds\1\Scratch\Test Build\Binaries\
  dir /s > C:\Builds\1\Scratch\Test Build\Binaries\Dir2.txt
  The system cannot find the path specified.
C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj(24,3): error MSB3073: The command "dir /s > C:\Builds\1\Scratch\Test Build\Binaries\Dir2.txt" exited with code 1.
Done Building Project "C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj" (default targets) -- FAILED.

Build FAILED.

"C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj" (default target) (1) ->
(Build target) -> 
  C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj(24,3): error MSB3073: The command "dir /s > C:\Builds\1\Scratch\Test Build\Binaries\Dir2.txt" exited with code 1.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.14

Am I going about this completely wrong?

+1  A: 

Your code works fine in my computer. However : you should instantiate OutDir property either by passing it in Command-Line invokation :

c:\WINDOWS\Microsoft.NET\Framework\v4.0\MSBuild.exe test.proj /p:OutDir=MyNewDir

or with a PropertyGroup element :

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;

  <PropertyGroup>
    <OutDir>MyNewDir</OutDir>
  </PropertyGroup>

 <Target Name="Build">
  <Message Text="Output Dir: $(OutDir)" />
  <MakeDir Directories="$(OutDir)" />
  <Exec Command='dir /s > \\ANetworkPath\dir.txt
    dir /s > "$(OutDir)\Dir2.txt"'/>
 </Target>
</Project>

Notice the \ added in the dir command.

EDIT : I get it : you have a space in your output path. The command dir /s > my path\Dir2.txt is not gonna work unless you encapsulate the path with quotes. Try the following commands in the dos shell :

mkdir C:\Builds\1\Scratch\Test Build\Binaries\
mkdir "C:\Builds\1\Scratch\Test Build\Binaries\"

You will notice the difference (the first line creates two directories one C:\Builds\1\Scratch\Test and one .\Build\Binaries). I edited my code above to add quotes.

Benjamin Baumann
Updated the question with the command line
Boarder2
Could you please post the output of your target?
Benjamin Baumann
Updated with output. Note that this is using TFS Build which is calling MSBuild. Not just MSBuild from the command line.
Boarder2
Ok I Edited my answer. You must add quotes to your command line!
Benjamin Baumann
Oh, you're exactly correct. It's always in the details, isn't it.
Boarder2
A: 

This will also work.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    <Target Name="Build">
        <Exec Command='dir /s > Dir2.txt'/>
        <Copy SourceFiles='Dir2.txt' DestinationFolder='$(OutDir)' />
    </Target>
</Project>
Boarder2