4

I created a solution that uses the Costura.Fody nuget package to merge referenced assemblies as embedded resources. I want this so that I can create a single exe for my application. This was working great for a while until I added a reference to SkiaSharp (specifically the nuget packages SkiaSharp and SkiaSharp.Svg). The libSkiaSharp.dll is not embedded and instead built in the startup project folder, and I can't run the program exe on its own unless I keep the dll in the same folder. Is there a way to fix this?

Here's the steps to reproduce this:

1. Create a new WPF project
2. Add the Costura.Fody and Fody nuget packages.
3. Add a file called FodyWeavers.xml with the contents set to this:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <Costura/>
</Weavers> 
  1. Build and run the exe file in the bin/Debug folder. Notice that program will start up even if you move the exe to a new location.
  2. Add SkiaSharp and SkiaSharp.Svg nuget packages.
  3. get an svg file and add it to your project directory
  4. add the following code to your MainWindow constructor:

    var svg = new SKSvg(); svg.Load("image.svg"); SKCanvas canvas = new SKCanvas(new SKBitmap()); canvas.DrawPicture(svg.Picture);

  5. notice that if you copy the image file and the exe and place in another directory, the exe will not start up. This occurs because it can't find libSkiaSharp.dll.

user2481095
  • 2,024
  • 7
  • 22
  • 32
  • By the way I think the reason for this issue has do to with the fact that the libSkiaSharp.dll is a native library. However I've a tried adding a reference to the libary in the FodyWeavers.xml file, using the IncludeAssemblies tag. But so far I haven't figured out how to get it to embed all dlls. – user2481095 Oct 10 '18 at 00:22

2 Answers2

3

Create a Costura32 and/or Costura64 folder in your project. Copy libSkiaSharp.dll into the appropriate directory depending on its bitness. Costura will automatically unpack and load native binaries from those directories.

Joel Lucsy
  • 8,520
  • 1
  • 29
  • 35
  • 1
    This was helpful because it does in fact work. However, if I were to update the SkiaSharp nuget package then those files could be out of date without someone knowing. Adding a post build event to copy the libSkiaSharp files from the debug folder to the Costura folders won't work because the files need to be referenced as embedded resources. A successful build depends on the files being there so they can't be copied post build. I also can't copy from the nuget package folder because there are different libSKiaSharp file for different versions of Windows. – user2481095 Oct 11 '18 at 01:14
  • What about setting up a pre-build event? – Joel Lucsy Oct 11 '18 at 13:13
  • I can't do a pre-build event either because the files have not been copied to the the debug folder at that point. They are copied after the project is built. It's frustrating because I know I can make it work, but it's not ideal. – user2481095 Oct 11 '18 at 17:35
  • Can you do two builds, start with a prebuild and embeding them on the second build? – MarkovskI Nov 07 '18 at 18:05
1

Have you tried the following:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <Costura>
    <IncludeAssemblies>
        libSkiaSharp
    </IncludeAssemblies>
  </Costura>
</Weavers>
Nekeniehl
  • 1,633
  • 18
  • 35
  • 2
    Build fails when I add this, with the following error: "Fody/Costura: Assembly 'libSkiaSharp' cannot be found (not even as CopyLocal='false'), please update the configuration" – user2481095 Nov 12 '18 at 18:21