0

What we want to do

  • I want to move the dylib in the resources directory to the output directory at build time.

The problem I am having

  • The resoucres directory is copied to the output directory, but the dylib cannot be found and executed because the directory structure is not correct.

Steps to reproduce

the directory structure of the project:

  • src directory contains the C# source code
  • resources directory contains the files that we want copied to the output directory. The directory structure in these files should be retained.
.
├── README.txt
├── Project.csproj
├── Project.sln
├── resources
│   ├── README.txt
│   ├── VERSION
│   ├── libonnxruntime.1.13.1.dylib
│   ├── libonnxruntime.1.14.0.dylib
│   ├── libvoicevox_core.dylib
│   ├── model
│   │   ├── predict_duration-0.onnx
...
│   │   ├── predict_duration-1.onnx
│   │   ├── predict_intonation-0.onnx
│   │   └── predict_intonation-1.onnx
│   ├── open_jtalk_dic_utf_8-1.11
│   │   ├── COPYING
│   │   ├── char.bin
│   │   ├── left-id.def
│   │   ├── matrix.bin
│   │   ├── pos-id.def
│   │   ├── rewrite.def
│   │   ├── right-id.def
│   │   ├── sys.dic
│   │   └── unk.dic
│   └── voicevox_core.h
└── src
...
    ├── Program.cs

Regarding csprj

  • ItemGroup is used to copy to the output directory.
  • I think it is not working correctly because of the wrong way to set this up. Project.csprj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <None Include="$(ProjectDir)\resources\**" Exclude="$(ProjectDir)\resources\.gitkeep" CopyToOutputDirectory="Always" Visible="false" />
  </ItemGroup>
</Project>

direcotry structure

output dirctory structure

  • The resources directory is created in the output directory.
  • What I am looking for is for the contents of the resources directory to be generated in the output directory.
bin
└── Debug
    └── net7.0
        ├── Project
        ├── Project.deps.json
        ├── Project.dll
        ├── Project.pdb
        ├── Project.runtimeconfig.json
        └── resources
            ├── README.txt
            ├── VERSION
            ├── libonnxruntime.1.13.1.dylib
            ├── libonnxruntime.1.14.0.dylib
            ├── libvoicevox_core.dylib
            ├── model
            │   ├── predict_duration-0.onnx
...
            │   ├── predict_duration-1.onnx
            │   ├── predict_intonation-0.onnx
            │   └── predict_intonation-1.onnx
            ├── open_jtalk_dic_utf_8-1.11
            │   ├── COPYING
            │   ├── char.bin
            │   ├── left-id.def
            │   ├── matrix.bin
            │   ├── pos-id.def
            │   ├── rewrite.def
            │   ├── right-id.def
            │   ├── sys.dic
            │   └── unk.dic
            └── voicevox_core.h

Expected Directory Structures

Here is the directory structure I am looking for, with the contents of the resources directory copied into the output directory.

└── Debug
    └── net7.0
        ├── README.txt
        ├── VERSION
        ├── Project
        ├── Project.deps.json
        ├── Project.dll
        ├── Project.pdb
        ├── Project.runtimeconfig.json
        ├── libonnxruntime.1.13.1.dylib
        ├── libonnxruntime.1.14.0.dylib
        ├── libvoicevox_core.dylib
        ├── model
        │   ├── predict_duration-0.onnx
...
        │   ├── predict_duration-1.onnx
        │   ├── predict_intonation-0.onnx
        │   └── predict_intonation-1.onnx
        ├── open_jtalk_dic_utf_8-1.11
        │   ├── COPYING
        │   ├── char.bin
        │   ├── left-id.def
        │   ├── matrix.bin
        │   ├── pos-id.def
        │   ├── rewrite.def
        │   ├── right-id.def
        │   ├── sys.dic
        │   └── unk.dic
        └── voicevox_core.h

Not sure why, but how it can be resolved.

  • Move resources directory to the parent directory and update csprj directory tree is this
├── Project
│   ├── README.txt
│   ├── Project.csproj
│   ├── Project.sln
│   └── src
│       ├── Program.cs
...
└── resources
    ├── README.txt
    ├── VERSION
    ├── libonnxruntime.1.13.1.dylib
    ├── libonnxruntime.1.14.0.dylib
    ├── libvoicevox_core.dylib
    ├── model
    │   ├── predict_duration-0.onnx
...
    │   ├── predict_duration-1.onnx
    │   ├── predict_intonation-0.onnx
    │   └── predict_intonation-1.onnx
    ├── open_jtalk_dic_utf_8-1.11
    │   ├── COPYING
    │   ├── char.bin
    │   ├── left-id.def
    │   ├── matrix.bin
    │   ├── pos-id.def
    │   ├── rewrite.def
    │   ├── right-id.def
    │   ├── sys.dic
    │   └── unk.dic
    └── voicevox_core.h
musako
  • 897
  • 2
  • 10
  • 26
  • 1
    by default any resources keep their path when copied to the resource directory. So your output structure is how I would expect it to be. Why do you expect files in the resource folder to be put in the root? What would happen if you had multiple resource folder with files with the same name? Can't you just add "resource\" to any file paths? or put the resources in the project root? – JonasH May 08 '23 at 10:59
  • One might have to add: the word ["resource"](https://learn.microsoft.com/en-us/dotnet/core/extensions/resources) does in fact have a specific meaning in the context of C#/dotnet projects. – Fildor May 08 '23 at 11:04
  • @JonasH I want to use it as a library and would like to copy it to the output directory at build time. – musako May 08 '23 at 11:17
  • @Fildor I tried converting the resource to lib, but the result was the same. – musako May 08 '23 at 11:18
  • 1
    Managed libraries are handled by adding a *reference* to the assembly. If you want to pInvoke native libraries, see [Relative path to unmanaged DLL](https://stackoverflow.com/questions/9256901/relative-path-to-unmanaged-dll) – JonasH May 08 '23 at 11:28
  • @JonasH I don't know why, but there is a way to make it work correctly. Why does it work if I move resources one directory parent ? – musako May 08 '23 at 11:44

0 Answers0