2

I'm working at WPF app. I'm trying to use Target Name="AfterBuild" ... to replace my .exe.config file with my Debug.config or Release.config (depends on current configuration.

My .csproj file contains the code:

  <Target Name="AfterBuild">
    <Delete Files="$(TargetDir)$(TargetFileName).config" />
    <Copy SourceFiles="$(ProjectDir)$(Configuration).config" DestinationFiles="$(TargetDir)$(TargetFileName).config" />
  </Target>

When I build my solution in Debug or Release configuration, it works well - my .exe.config file is replaced with file I want to.

BUT when I try to RUN (F5) my application, it just takes App.config (which is default) and renames it into .exe.config without any replacing. Or, may be, replaces correctly at first and after that - replaces again with App.config. I can't determine it exactly. But in result - I get "pure" App.config without any changes.

So how can I enforce MSBuild not only use my "changed" configs to replace during build, but to replace during run too.

Thank you

Ivan Zorin
  • 51
  • 5
  • 1
    This seems like the type of question that begs asking "what are you really trying to do"? Based on your snippet, are you using one of the techniques in http://stackoverflow.com/questions/8082662/how-to-select-different-app-config-for-several-build-configurations? Can you give more details about the differences you want you app to have between debug/release? – Kory Gill Jan 13 '16 at 19:03
  • Why don't you just delete app.config from solution? – csharpfolk Jan 13 '16 at 19:48
  • 2 Kory Gill Yes, exactly! I'm using #2. I'd like to stop/launch Windows service with my app, and in debug I'd like to work with service on my PC, and in Release - with one on prod server. So PC name (to complete the adress in powershell cmdlet) I'd like to store in config file. It's just a string. – Ivan Zorin Jan 13 '16 at 20:08
  • 2csharpfolk I can't delete it because in my code I'm using something like Properties.Settings.Default.Server where Server - is app setting, which taken from .config. Of cause I can refuse this way and use usual text file (xml, csv e t.c.), but it is config info and we have config file to store config info - I'd like to use it. – Ivan Zorin Jan 13 '16 at 20:11
  • 1
    When you debug, the *real* config file name is yourapp.vshost.exe.config Project > Properties > Debug tab, untick the "Enable the Visual Studio hosting process" checkbox. – Hans Passant Jan 13 '16 at 20:51

0 Answers0