Copying files into the application folder at compile time

前端 未结 8 1170
无人共我
无人共我 2020-12-02 08:25

If I have some files I want to copy from my project into the .\\bin\\debug\\ folder on compilation, then it seems I have to put them into the root of the projec

相关标签:
8条回答
  • 2020-12-02 08:37

    You want to use a Post-Build event on your project. You can specify the output there and there are macro values for frequently used things like project path, item name, etc.

    0 讨论(0)
  • 2020-12-02 08:39

    Personally I prefer this way.

    Modify the .csproj to add

    <ItemGroup>
        <ContentWithTargetPath Include="ConfigFiles\MyFirstConfigFile.txt">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <TargetPath>%(Filename)%(Extension)</TargetPath>
        </ContentWithTargetPath>
    </ItemGroup>
    

    or generalizing, if you want to copy all subfolders and files, you could do:

    <ItemGroup>
        <ContentWithTargetPath Include="ConfigFiles\**">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <TargetPath>%(RecursiveDIr)\%(Filename)%(Extension)</TargetPath>
        </ContentWithTargetPath>
    </ItemGroup>
    
    0 讨论(0)
  • 2020-12-02 08:39

    You can use the PostBuild event of the project. After the build is completed, you can run a DOS batch file and copy the desired files to your desired folder.

    0 讨论(0)
  • 2020-12-02 08:45

    You can also put the files or links into the root of the solution explorer and then set the files properties:

    Build action = Content

    and

    Copy to Output Directory = Copy if newer (for example)

    For a link drag the file from the windows explorer into the solution explorer holding down the shift and control keys.

    0 讨论(0)
  • 2020-12-02 08:47

    You could do this with a post build event. Set the files to no action on compile, then in the macro copy the files to the directory you want.

    Here's a post build Macro that I think will work by copying all files in a directory called Configuration to the root build folder:

    copy $(ProjectDir)Configuration\* $(ProjectDir)$(OutDir)
    
    0 讨论(0)
  • 2020-12-02 08:50

    copy from subfolder to subfolder

     if not exist "$(ProjectDir)$(OutDir)subfolder" mkdir "$(ProjectDir)$(OutDir)subfolder"
    
     copy "$(ProjectDir)subfolder\"  "$(ProjectDir)$(OutDir)subfolder\"
    
    0 讨论(0)
提交回复
热议问题