31

There is a Windows Forms (NET 3.5) project, foo.csproj, with localized resources files. I use MSBuild to build the project and create a deployment structure:

<MSBuild Projects="foo.csproj" Properties="Configuration=Release;OutputPath=..\deploy\foo" Targets="Build" />

It copies foo.exe and all localized DLL files to the deploy\foo folder, but I need localized DLL files to be copied into a separate folder. It should be:

  • deploy\foo\foo.exe
  • deploy\locales\ru-RU\foo.resources.dll
  • deploy\locales\pt-BR\foo.resources.dll

Is there a way to configure MSBuild to copy EXE and DLL files to different folders?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
wince
  • 511
  • 1
  • 5
  • 13
  • If you speak about resx files, They should be generated and copied in a subfolder corresponding to the culture name during the `GenerateSatelliteAssemblies` and `CopyFilesToOutputDirectory`. How did you name your resource files ? – JoeBilly Oct 28 '13 at 14:17
  • Yes, I mean resx files. I added Res.resx, Res.ru-RU.resx etc files to the project and msbuild creates these subfolders in the output folder - the same place it creates foo.exe file. But I need these subfolders to be copied to the separate location - deploy\locales – wince Oct 29 '13 at 07:13

2 Answers2

52

Using MSBuild command line, you can specify the output path like below:

C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe <path_to_project_file> /t:Build /p:OutDir=c:\custom_build_out\;Configuration=PRODUCTION;Platform=x64

Note:

  1. If you change the order of specifying the OutDir property for /p, this doesn't work.
  2. The OutDir property is for specifying a full path to an alternate directory. OutputPath is for a relative directory.
  3. It has to have a project name + build configuration name in the custom build output path as MSBuild does not append these things to the OutDir.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jerome Anthony
  • 7,823
  • 2
  • 40
  • 31
  • This was perfect! I had to change the order and that was it, unblocked! ^_^ – kayleeFrye_onDeck Jul 19 '17 at 17:38
  • 1
    This is not working for me with ToolsVersion="14.0", the MSBuild is unable to locate references. I am copying manually with powershell. – Carlos ABS Feb 28 '18 at 19:31
  • Hi, can you check this question please https://stackoverflow.com/questions/61661254/msbuild-task-on-azure-devops-with-different-configuration-for-dependent-project – Newton Sheikh May 08 '20 at 08:26
9

Resource files generation and copy is done in an internal MSBuild process during the build: GenerateSatelliteAssemblies and CopyFilesToOutputDirectory. They are copied in the output directory.

As far as I know, you can't modify this behavior.

You have to move your resources files after the build step. I would advise to use the Move task from MSBuild community tasks.

<MSBuild Projects="foo.csproj" Properties="Configuration=Release;OutputPath=..\deploy\foo" Targets="Build" />

<CreateItem Include="..\deploy\foo\**\*.resources.dll">
    <Output TaskParameter="Include" ItemName="ResourcesToMove" />
</CreateItem>

<Move SourceFiles="@(ResourcesToMove)" DestinationFiles="@(ResourcesToMove->'..\deploy\locales\%(RecursiveDir)\%(Filename)%(Extension)')"/>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JoeBilly
  • 3,057
  • 29
  • 35
  • Thanks, I guess this is a solution. I will try that msbuild community tasks now. – wince Oct 29 '13 at 10:33
  • This answer may be a little overkill for you. Consider trying out Jerome's answer first to possibly save yourself some time. – kayleeFrye_onDeck Jul 19 '17 at 17:39
  • This anwser is about copying **some** output files in a different folder (compiled resx in this case). Modifiing the whole output path of the build with a command line does not answer to the specific question even if it covers the question title "Configuring msbuild output path" - which can be done in a lot of various ways. – JoeBilly Aug 29 '18 at 15:28