Implement BeforePublish as in AfterBuild

I have two application config files (app.debug.config and app.production.config), I found this solution to copy the config file to output folder according to the current build config 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 build configuration (Production), MSbuild will automatically copy the app.production.config file and rename it to projectname.config in the output folder.

Unfortunately this is not the same for publishing because when I published the project to the web server the config file will not be published.

how can i do the same task for publishing?

+3


source to share


1 answer


I found a 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>

      

+1


source







All Articles