|
Hi, I tried many solutions but the one that is similar to the code example is this : I even tried to add the logo directory in the path C:\Users\jmruf\source\repos\BddAgora\BddMain\bin\Debug\net10.0\Logo\C_agora-new-logo-200x200.png (it seems to me that isn't a good idea), so I had to transform the imagePath string because I receive a "net10.0-windows" subdirectory that doesn't exist (it's only "net10.0"). I don't know what I missed in the code example that could force relative path in my project directory. |
Replies: 2 comments 1 reply
|
Add these two lines above your check to see it: Debug.WriteLine($"CWD: {Environment.CurrentDirectory}");
Debug.WriteLine($"Base: {AppContext.BaseDirectory}");Both point into 1. Make the file land in the output folderIn <ItemGroup>
<None Update="Logo\C_agora-new-logo-200x200.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>Or in Solution Explorer: select the file, press Alt+Enter, set Copy to Output Directory to Copy if newer (in a French VS: Copier dans le répertoire de sortie → Copier si plus récent). After a rebuild, 2. Anchor the path to the assembly rather than the working directorystring imagePath = Path.Combine(AppContext.BaseDirectory, "Logo", "C_agora-new-logo-200x200.png");
Step 1 alone makes it work today; step 2 keeps it working. About the
|






Glad it works.
Your addition is the key detail for anyone finding this later: in a multi-project solution, both
Environment.CurrentDirectoryandAppContext.BaseDirectoryresolve against the startup project —BddMainhere — not against the project whose code happens to be executing.BddPDFasking forLogo/...therefore looks insideBddMain's output folder. That is also why the framework moniker you saw wasnet10.0-windowsrather thannet10.0:BddMaintargets Windows,BddPDFdoes not.Worth keeping in mind if you later move the logo into
BddPDFitself — the file still has to end up in the startup project's output directory to be found at that relative path.If this resolved it, could you ma…