Simulating App.config behaviour

I would like to be able to have App.myconfig files copies to the output directory like AssemblyName.myconfig, like it happens with App.config files. How can I do that without creating the targets from scratch

Answer this question

Simulating App.config behaviour

  • Mike_1232123432

    Are you using a project file within Visual Studio If so, just set the "Copy Local" property on the app.myconfig file to "Copy If Newer" or "Copy Always".

    Neil

  • cmb1

    Oh, I get it. You want to rename them when they get copied. You can certainly do this by adding a custom AfterBuild action and using transforms, but let me ask the team and see if there's an easier way.

    Neil

  • Jonathan Eden

    Ovatsus,

    Just add the following just before the </Project> tag:

      <Target Name="AfterBuild"
                 Inputs="@(MyFilesToCopy)"
                 Outputs="@(MyFilesToCopy ->'$(OutputPath)%(TargetPath)')" >

      <Copy SourceFiles="@(MyFilesToCopy)"
                DestinationFiles="@(MyFilesToCopy ->'$(OutputPath)%(TargetPath)')"/>

      </Target>


    This assumes you have an item in your project like

      <ItemGroup>
        <MyFilesToCopy Include="foo.myconfig">
          <TargetPath>$(AssemblyName).myconfig</TargetPath>
        </MyFilesToCopy>
      </ItemGroup>


    with TargetPath defined. You can change the item name, etc as you like.

    Dan



  • MS_ISV

    I'm doing that, but that doesn't change the filename, just copies the file as is.
  • Simulating App.config behaviour