0

Our solution has many dependencies that are not references, they are script files (whole Python projects using .pyproj) and DLLs loaded using reflection (MEF actually).

We are using post build events to copy those files to the correct output directory when compiling the main exe. This has become unwieldy since we now have multiple entry exes that need those files and the amount of copies done is unmanageable.

This creates two problems: first, synchronizing all the projects to use the same sequence of post build events; second, xcopying the files seems to fail sometimes and from our experience is not always reliable.

Are there more manageable alternatives for copying build outputs at compile time without using xcopy in post build events?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ziv
  • 2,755
  • 5
  • 30
  • 42
  • Time to change your build directory perhaps. Using bin/Debug is just a convention, you can make it anything you want. Clearly you'll be greatly ahead by building to a directory that already has those files present. So no copying is required. – Hans Passant Sep 20 '15 at 08:11
  • Actually, there is an output directory, it's just that not all exes compile into it. I could move the output there, but it doesn't 100% solve the problem of the python files that still need to be copied into the output directory in one the projects. – Ziv Sep 20 '15 at 09:13

1 Answers1

0

You can use MSBuild Copy task - it has several parameters that makes it more powerful rather than copy/xcopy friends from cmd. I believe that you are using build server (or type of this) to run msbuild command, so you are able to pass some additional parameters to extend your build process. If the amount of projects that need to perform copy operation is not large (up to 10 or so), you can use AfterBuild target to perform copy task:

<Target Name="AfterBuild">
    <Copy SourceFiles="@(MySourceFiles)"
        DestinationFolder="$(MyOuputPath)" />
</Target>

Where MySourceFiles is the msbuild item used to describe all files you need to copy.

You can try the solution from this thread

If the amount of projects is large - let me assume that the list of the files to be copied is the permanent, and you primarly focused on the c# project. You can create separate msbuild project, where you can specify this list, and the target to be executed:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <BuildDependsOn>
        $(BuildDependsOn);
        CopyDynamicLibrary
    </BuildDependsOn>
    <MyOuputPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(Platform)\</MyOuputPath>
  </PropertyGroup>
  <ItemGroup>
    <MySourceFile Include="$(MSBuildThisFileDirectory)Dir\File.ext" />
    <MySourceFile Include="$(MSBuildThisFileDirectory)Dir\File1.ext" />
    <!-- etc -->
  </ItemGroup>

  <Target Name="CopyDynamicLibrary">
      <Copy SourceFiles="@(MySourceFiles)"
            DestinationFolder="$(MyOuputPath)" />
  </Target>
</Project>

After you have this file, you can run msbuild command like the following:

msbuild /* YourParameters */ /p:"CustomAfterMicrosoftCSharpTargets=PathToCommonFile"

Here CustomAfterMicrosoftCSharpTargets is the property used by Microsoft.CSharp.targets file to import project specified in it at the end.

You have large number of extensibility with msbuild, you only need to choose the right one.

Community
  • 1
  • 1
stukselbax
  • 5,855
  • 3
  • 32
  • 54