Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Native files are not being copied to the output directory in NetFramework #127

Closed
Jonhops1595 opened this issue Apr 19, 2024 · 3 comments · Fixed by #131
Closed

[BUG] Native files are not being copied to the output directory in NetFramework #127

Jonhops1595 opened this issue Apr 19, 2024 · 3 comments · Fixed by #131
Assignees
Labels
bug-windows-only This bug is only spawns on windows enhancement New feature or request
Milestone

Comments

@Jonhops1595
Copy link

Describe the bug
I have a .netstandard2 project that references consumes MaxRev.Gdal.Core and MaxRev.Gdal.WindowsRuntime.Minimal through Nuget (Let's call this ClassLibrary1). This project is built into a nuget package and consumed by a .Net Framework 4.7.2 console app (Let's call this ConsoleApp2) . When running the GdalBase.ConfigureAll() function, I get an error: Unable to load DLL 'gdal_wrap'. The specified module could not be found.

Viewing the bin of ConsoleApp2, I can verify that gdal_wrap.dll is there in the runtimes folder:
ConsoleApp2\bin\Debug\runtimes\win-x64\native\gdal_wrap.dll

ClassLibrary1 (.netstandard2):

using System;
using MaxRev.Gdal.Core;

namespace ClassLibrary1
{
    public static class Class1
    {
        static Class1()
        {
            GdalBase.ConfigureAll();
        }        

        public static int NumberFunction()
        {
            return 1;
        }
    }
}

ConsoleApp2 (.Net Framework 4.7.2):

using System;
using ClassLibrary1;

namespace ConsoleApp2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting");
            if (Class1.NumberFunction() == 1)
            {
                Console.WriteLine("Success");
            }
        }
    }
}

Is this the expected behavior due to the .NET framework and .NET standard capability? Is there any way to use MaxRev.Gdal.Core in .NET Framework 4.7.2?

Environment information:

  • OS: Windows 10
  • Package version (core): MaxRev.Gdal.Core 3.8.3.286
  • Package version (runtime): MaxRev.Gdal.WindowsRuntime.Minimal 3.8.3.259

Additional context
This is just example code to reproduce and illustrate the problem found in a larger application.

@Jonhops1595 Jonhops1595 added the bug Something isn't working label Apr 19, 2024
@MaxRev-Dev
Copy link
Owner

MaxRev-Dev commented Apr 19, 2024

@Jonhops1595 thanks for creating this issue. I can confirm that it requires packaging some additional build target files specific to NetFramework in order to copy files during the build to the output directory.

For now, as a workaround, you can create a similar file within your library project. I'll include it in the next release.
Another solution is to switch to net480 and csproj and package reference instead of packages.config. I had successfully loaded GDAL in net480 adding Nuget packages via PackageReference.

@MaxRev-Dev MaxRev-Dev changed the title [BUG] Unable to load DLL 'gdal_wrap'. The specified module could not be found. [BUG] Native files are not being copied to the output directory in NetFramework Apr 19, 2024
@MaxRev-Dev
Copy link
Owner

You need only to migrate to Nuget PackageReference https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference to make it work.

As I mentioned above, the old package.config doesn't automatically copy package dependencies to the output directory.

@MaxRev-Dev MaxRev-Dev added enhancement New feature or request bug-windows-only This bug is only spawns on windows and removed bug Something isn't working labels Apr 19, 2024
@Jonhops1595
Copy link
Author

Thank you @MaxRev-Dev. Using PackageReference worked for the demo project. I am now working on implementing this in the larger application. I'll comment when I get that working as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-windows-only This bug is only spawns on windows enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants