20

I know how to select files that I want copied to the output directory of my build via Properties=>Copy Always, but I haven't been able to find a way to copy a different file depending on the build type.

I have two separate config files, one set up for local development (ie. should be copied on debug build only) and one that is set up for the server environment (ie. should be copied on release build only).

Does anyone know how to achieve this type of conditional functionality?

PseudoPsyche
  • 4,332
  • 5
  • 37
  • 58
  • 1
    check the answer by Romeo at the bottom of the page: http://stackoverflow.com/questions/8082662/how-to-select-different-app-config-for-several-build-configurations – Bayeni Dec 05 '14 at 14:24
  • I'll try that, but it looks like it's mainly for the VS app.config file. Will this work for copying my own custom config file that my app reads? – PseudoPsyche Dec 05 '14 at 14:28
  • Is this a application that will be running inside IIS? (There are features I know about built in to do this but they only work on ASP.NET and similar projects) – Scott Chamberlain Dec 05 '14 at 14:37
  • @Bayeni, with a couple of small tweaks, that worked! – PseudoPsyche Dec 05 '14 at 14:39
  • @ScottChamberlain, no this is a helper console application that will be called in the background by another application, which I believe is running inside IIS. – PseudoPsyche Dec 05 '14 at 14:41

2 Answers2

28

Currently I have achieved the desired functionality by using a slight modified version of the answer in this post that @Bayeni shared: https://stackoverflow.com/a/8083060/1428743

This is currently working for me, but if there is a better way to go about this please let me know.

  <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
    <Content Include="local.cfg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup Condition=" '$(Configuration)' == 'Release' ">
    <Content Include="release.cfg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
Community
  • 1
  • 1
PseudoPsyche
  • 4,332
  • 5
  • 37
  • 58
0

Why don't you use a PostBuild event and call xCopy to copy the files you need?

Chris
  • 5,040
  • 3
  • 20
  • 24
  • Is there any benefit to this over the method suggested in the post shared by @Bayeni? Adding conditional `Item Group` entries with file includes to the `.csproj` file? – PseudoPsyche Dec 05 '14 at 14:44
  • I added an answer to this question to show the method that is currently working for me. If there any any benefits to your proposed solution, please comment. – PseudoPsyche Dec 05 '14 at 14:50
  • It is similar to the `` option but you have to choice to call an number of programs (xCopy) and get some output out of it as well (say a log file) – Chris Dec 05 '14 at 14:52