Including content files in .csproj that are outside the project cone

前端 未结 7 1758
忘掉有多难
忘掉有多难 2020-11-27 12:09

I have a C# project say MyProject.csproj located at \"C:\\Projects\\MyProject\\\". I also have files that I want copied into the output directory of this project. But, the f

7条回答
  •  再見小時候
    2020-11-27 12:37

    The answer of Mandark adds the content files directly to the solution, and they will show up in the solution explorer. Whenever a file is added or deleted in the original directory, this is not picked up by visual studio automatically. Also, whenever a file is deleted or added in the solution explorer, the project file is altered, and all files are included separately, instead of just including the folder.

    To prevent this, you can use the same trick, but put it in a separate project file and then import it.

    The project file (for example include.proj) looks like this:

    
    
    
      %(RecursiveDir)%(Filename)%(Extension)
      PreserveNewest
    
    
    
    

    In your own project file, add the following line

    
    

    Visual Studio will not mess with this file, and just adds files as content during a build. Changes in the original directory are always included. The files won't show up in your solution explorer, but will be included in the output directory.

    Picked up on this trick here: http://blogs.msdn.com/b/shawnhar/archive/2007/06/06/wildcard-content-using-msbuild.aspx

提交回复
热议问题