3

I have two application config file (app.debug.config and app.production.config), I found this solution to copy the config file to output folder according to the current build configuration name:

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

so after selecting for example the (Production) build configuration, the MSbuild will automatically copy the app.production.config and rename it to projectname.config in the output folder.

unfortunately it is not the same case for publishing, because when I published the project to a web server, the configuration file is not published.

how can I do the same task for publishing?

Nour
  • 5,252
  • 3
  • 41
  • 66
  • if you right click on your app.production.config and click properties, what value does it show next to the 'copy to output directory' field? – Dave Alperovich Jan 26 '13 at 05:17
  • Take a look at this: http://msdn.microsoft.com/en-us/library/ms366724%28v=vs.100%29.aspx and this http://stackoverflow.com/questions/12899650/why-does-msbuild-ignore-my-beforepublish-target – Irvin Dominin Jan 26 '13 at 08:30

1 Answers1

1

I found out the solution, I added the following to the project file:

  <ItemGroup>
    <CustomConfigFile Include="$(ProjectDir)\App.$(Configuration).config">
      <Visible>False</Visible>
    </CustomConfigFile>
  </ItemGroup>
<Target Name="BeforePublish">
<CreateItem Include="@(CustomConfigFile)" AdditionalMetadata="TargetPath=$(TargetFileName).config;IsDataFile=false">
      <Output TaskParameter="Include" ItemName="_DeploymentManifestFiles" />
    </CreateItem>
</Target>
Nour
  • 5,252
  • 3
  • 41
  • 66
  • do you know how to move a file instead? – drzaus Aug 21 '13 at 17:51
  • No, actually I don't, I'm not that expert in MSBuild, However in VS 2012 this workaround failed, and Microsoft declared that this not official technique !! and I have to use the link file instead to copy it while publishing ! – Nour Aug 22 '13 at 10:00