Automatic copy files to output during application building

后端 未结 8 1770
死守一世寂寞
死守一世寂寞 2020-12-07 22:48

There is Copy to Output Directory property for files in C# projects. But in VC++ projects it is absent. I know, that I can use Build events in VC++ and wri

8条回答
  •  时光说笑
    2020-12-07 23:00

    Following henri-socha's answer about VS2015 (and probably VS2013 and VS2012, or anything using MSBuild style projects), the ItemGroup item type is important.

    Specifically items do not seem to be copied, whereas items do.

    So, for a project directory Data containing a text file ThisIsData.txt, this will create a subdirectory Data under the $(OutDir) directory and copy the file ThisIsData.txt from the project into it if it's newer:

    
      
        PreserveNewest
      
    
    

    This won't, although it is what the Visual Studio IDE will insert if you add the text file to your project, and set the Content property to True.

    
      
        true
      
    
    

    So in other words you need to add the file via the IDE to make it realise the file is included in the project (which adds tag ItemGroup), and then open the project in a text editor and add the tag ItemGroup to get it to do what you want.

    I'm not sure what the tag actually does. It may be a remnant since the only MSDN reference I could find considers it archived: https://msdn.microsoft.com/en-us/library/aa712517.aspx

提交回复
热议问题