Copying Visual Studio project file(s) to output directory during build

后端 未结 8 1890
梦毁少年i
梦毁少年i 2020-12-03 00:29

When I build a Visual Studio project, the executable is written to the output directory specified in the projects Property Page.

I have a project that has some extra

相关标签:
8条回答
  • 2020-12-03 01:20

    While I was searching the file’s Property Page for a build-action field, I had a thought: set the custom build step to copy the file (manually). This turned out to be easier than I thought. I had figured it would require using cmd or other external executable (xcopy, robocopy, etc.), but that is not necessary.

    I set the Custom Build Step as follows:

    Command Line : copy $(InputFileName) $(OutDir)
    Description  : Copying foobar...
    Outputs      : $(InputFileName)
    

    Setting the outputs field (correctly) was critical in order to prevent VS from always thinking the project is out of date and requiring to be rebuilt (I’m not certain if it needs to be prefixed with $(OutDir)\).

    It is reflected in the Output window as such:

    Copying foobar...
            1 file(s) copied.
    Compiling resources...
    Linking...
    
    0 讨论(0)
  • 2020-12-03 01:34

    For copying a files to the output directory in Visual Studio 2003 you could use Post-Build event:

    1. Right click on the project->Properties
    2. Common Properties->Build Events
    3. Set Post-Build Event Command Line to:

      xcopy /y $(ProjectDir)my_file.ini  $(ProjectDir)$(OutDir)
      
    4. OK and build!

    0 讨论(0)
提交回复
热议问题