简体   繁体   中英

How to make mono copy data files into subdirectory the same way visual studio does

I have a C# project which references a shared project. The shared project includes a lot of data I want copied in a folder, eg

Data/file1.txt

When built with visual studio, all the files move over to the output directory with a subfolder, eg

bin/Release/Data/file1.txt

but on mono, it ignores the subdirectory, eg

bin/Release/file1.txt

How can I force mono to maintain the same directory structure during the build?

As an update, during the build I see the following as well:

Target _CopyDeployFilesToOutputDirectoryPreserveNewest:
    Copying file from 'Data/file1.txt' to 'bin/Release/file1.txt'

UPDATE : This appears to be a bug in Xamarian Studio 5.9.4. Shared projects with items flagged as Copy to Output Directory will not respect the directory structure that they have in the Project...

Assuming:

  • MonoDevelop / Xamarian Studio 5.9.x+
  • Project is flagged to use MSBuild in the Project Options / Build / General panel
  • Project is a .shproj (bug, other project types are ok)

Set the File Properties to:

  • Copy to Output Directory

在此输入图像描述

Build and you should have:

.
├── AGenericFile.txt
├── Data
│   ├── Data2
│   │   └── file2.txt
│   ├── SharedData.txt
│   └── file1.txt
├── Data2
│   └── file3.txt
├── foodata.exe
└── foodata.exe.mdb

If you are still having problems, look at your project xml and make sure that your have a

<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

set on each of those data files.

Project / Tools / Edit file:

~~~
  <ItemGroup>
    <Folder Include="Data\" />
    <Folder Include="Data\Data2\" />
    <Folder Include="Data2\" />
  </ItemGroup>
  <ItemGroup>
    <None Include="AGenericFile.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="Data\file1.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="Data\Data2\file2.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Include="Data2\file3.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
~~~

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM