-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add build support for .NET core #1368
Comments
@rouault .Net Standard is considered to be a subset of .Net core and any other framework implementations. By targeting .NET Standard, you can build libraries that you can share across all your .NET apps, no matter on which .NET implementation or OS they run. This is basically for class libraries (like for gdal_csharp.dll and ogr_csharp.dll). The console applications should target .NET Core as a minimum requirement. For more info see: https://msdn.microsoft.com/en-us/magazine/mt842506.aspx |
Is there any progress on this? |
This gets a little bit urgent. Spatial support was added to EF Core 2.2, which is EOL - and Asp.Net Core 3.1 (the current LTS release) is without support for the classic .Net Framework. So, going back to 2.1 (the last LTS) is not an option. Being stuck to the 2.2 release is not good, since there was recently a security patch on the 2.1 release, which will not get ported to 2.2. Porting this library to .Net Standard 2.0 should be the way to go. |
@szekerest @rouault Will this be in one of the upcoming releases? |
Batchfile code I'm using to generate the .NET Standard 2.0 files: rem Build the old wrap and csharp DLLs
cd swig\csharp
nmake -f makefile.vc interface MSVC_VER=1920 WIN64=1
nmake -f makefile.vc ogr_dir gdal_dir osr_dir const_dir gdal_csharp MSVC_VER=1920 WIN64=1
nmake -f makefile.vc install MSVC_VER=1920 WIN64=1
rem Remove the .NET Framework files
del "%GDAL_HOME%\csharp\*_csharp.dll"
rem Now make the .netstandard wrappers
setlocal ENABLEDELAYEDEXPANSION
set PROJECT_FILE_DEF=^<Project Sdk="Microsoft.NET.Sdk"^>^<PropertyGroup^>^<TargetFramework^>netstandard2.0^</TargetFramework^>^<AssemblyVersion^>3.1.2.0^</AssemblyVersion^>^</PropertyGroup^>^</Project^>
echo !PROJECT_FILE_DEF! > const\gdalconst_csharp.csproj
echo !PROJECT_FILE_DEF! > osr\osr_csharp.csproj
echo !PROJECT_FILE_DEF! > ogr\ogr_csharp.csproj
echo !PROJECT_FILE_DEF! > gdal\gdal_csharp.csproj
endlocal
cd const
dotnet build -c Release -o "%GDAL_HOME%\csharp" -r win-x64
cd ..
cd osr
dotnet build -c Release -o "%GDAL_HOME%\csharp" -r win-x64
cd ..
cd ogr
dotnet add reference ..\osr\osr_csharp.csproj
dotnet build -c Release -o "%GDAL_HOME%\csharp" -r win-x64
cd ..
cd gdal
dotnet add reference ..\osr\osr_csharp.csproj ..\ogr\ogr_csharp.csproj
dotnet build -c Release -o "%GDAL_HOME%\csharp" -r win-x64
cd ..\..\..\..\.. |
@BrannonKing Thank you for sharing this, it looks very cool. I'll be trying to incorporate it in the makefiles |
A few notes:
|
The recent changes you put in are close. It looks like there is an issue with copying (installing) the *_csharp.dll files in that the makefile expects them to be in the csharp folder. In actuality they are in csharp/ogr, csharp/ogs, csharp/gdal, etc. |
Good point about the install target. I've never used that. Applying a fix for the problem. |
My previous statement wasn't entirely correct. It looks like those csproj files by default install files to |
@BrannonKing I don't see the problem. The build commands contain -o "." with causes that the result is generated into the same directory as the sources. |
Looking at this again today, the |
…ignature during tests (OSGeo#1368)
…ignature during tests (OSGeo#1368) (OSGeo#3332)
Is there any chance that this will be released any time soon? |
@rouault @szekerest - I was looking through any other issues that should be included in #5046. Given that the new CMake build scripts are building on Net5.0 - should we close this issue or move any remaining concerns to #5046 ? |
@jany-tenaj - can you be more explicit about what you are expecting to be released? The main repo makefile.vc on Windows has been building on NET Standard 2.0 and Net Core for a couple of years now? |
@runette we use the nuget packages for Gdal, Gdal.Plugins and Gdal.Native in .Net 4.7.2. I was trying to move our source code to .Net 6, but could not add the nuget packages. At the time I left my comment this here read like it could be what we needed. |
@jany-tenaj The NuGET packages are not managed as part of the GDAL repository - you need to talk to the maintainers directly and not through here. As far as GDAL is concerned, the change from .NET 4.7.2 was "released" a long time ago. When the CMake build scripts are merged - you will be able to locally create NuGET packages based on .NET 5. Keep an eye on that PR I linked to. |
@jany-tenaj I'm planning to create a netcore nuget build for Gdal, Gdal.Plugins and Gdal.Native, but there are a couple of issues I prefer to address before those packages are released. |
@szekerest that sounds good. Any idea how long we'll have to wait? |
Hi everyone, I'm the maintainer of unofficial gdal.netcore packages. It all started as a pet project, and currently, I'm trying to build them on my own in my free time. I do not know if you would be interested in contributing, but asking is better than assuming. A huge thanks to the maintainers of this repo, for the frequent updates and continuous support. |
Historically I've gone to @szekerest and his maintained site for the .net packages and wrappers. I think what he has done is what is most widely used. I may be wrong, but those wrappers are created via swig in this repository and get daily built for ease of use through that site. |
@jsmith-pathway The current versions of the packaging scripts for Gdal, Gdal.Plugins, and Gdal.Native can be found here https://github.com/gisinternals/buildsystem/tree/refactor/nuget However I'm still uncertain about what is the most reasonable concept to release the GDAL environment including a number of unmanaged dlls in nuget packages. With these packages an initialization source code is also emitted to the target project to set up the necessary environment settings, but it might not be so convenient in most cases. |
@szekerest yes, I'm familiar with the gisintenals build system. It wrote on VB, uses compile-time templates, and nuspec targets. For me, it's way too complicated to maintain but still, it's a good automation tool. So about initialization - all core logic and C# bindings are shipped in the main MaxRev.Gdal.Core package. Please note, there is no hardcoded list of drivers in build pipeline (like in nuspec), only in build requirements shared between make/nmake platforms. |
@szekerest We're using the initialization C# file that is shipped with the nuget package. Based on the fact that there isn't much gdal documentation for C# I'm glad we didn't have to figure that out ourselves. ;) The vb version we simple delete. It would be nice if the vb version wouldn't be added to C# projects. I think if you add those initialization files people have a chance to get started. Those who don't need them because they have their own can delete them. If the way things are done changes, we don't have to worry why the old code is no longer working, but get the new code that works. |
@MaxRev-Dev Thank you, it looks like your startup code in compiled into the dll instead of adding that in the source code. I'm not entirely sure which one is the better, but I'd somewhat prefer not to have a startup code at all, assuming the binaries can be deployed in relative locations to the executable. I'd also keep support for both the .net framework and .net core with both x86 and x64 versions in the package, but it is still not trivial to me how the AnyCPU setting is handled with a .net core build. Also referring to dll-s targeting the netstandard runtime doesn't seem to be supported with .net framework earlier than 4.6.1 so I'd probably need to provide a .net 4.x compatible version side by side. |
@jany-tenaj That is relatively easy to implement in a custom script for the project that using the older packages.config method. The projects using the newer PackageReference approach, are supported by the contentFiles item in nuspec which considers the language dependency. |
@szekerest After bootstrapping, it just does not create a mess in the user's project folder. As it shipped as a library, all code should be internal and closed for changes. Additional configuration can be provided, for example, via a fluent API pattern.
By default, all projects are configured with AnyCPU. At startup, this configuration performs a lookup for target platform binaries. Anyway, you can combine target architectures in a package as you want. Ideally, the package folder structure looks like this:
Useful sources: |
Having used the package by @MaxRev-Dev, I quite enjoyed that it just works ™ without any project folder pollution, dlls to take care of, or anything else really. It was way nicer to use than previous ways of interfacing with Gdal we used at our company, where we typically had some issues sooner or later. Just a random observation since the topic of ease of use and cleanliness came up. |
@MaxRev-Dev Thanks for the information and the links.
How the fluent api pattern is currently implemented in your packages? Which is the target interface on which the pattern is being executed? Are you using something exising like IHostBuilder?
This probably depends on how the compiler is invoked. I mostly use 'dotnet build' in the build scripts and that seems to rely on the Platform environment setting by default. For example an x64 Visual Studio Command Prompt builds x64 assemblies by default. However that can be controlled by adding the corresponding setting in the csproj file or in the build command line. There are many further issues I always encounter when building just a simple project and the documentation is very poor on that. For example if I specify the output folder to the current folder it doesn't compile the sources in the project directory: mkdir sampe The resulting assembly will not contain the code in the sample namespace. However specifying a directory like -o "..\build" would work. |
CSharp: Switch default platform target to AnyCPU #1368
CSharp: Switch default platform target to AnyCPU #1368
I think the current build is now working with either netcore and netframework 4.6.1 or above. The corresponding nuget packages GDAL, GDAL.Native and GDAL.Plugins have now been pushed. The new cmake build system (targeting GDAL 3.5) will replace this nmake based build configuration, but we strive to make the result compatible. Closing this issue now. |
[Backport release/3.4] CSharp: Switch default platform target to AnyCPU #1368
Use Gdal.Native to convert data into a dxf file. The EntityHandle is 0 (approximately on line 1150). In dxf syntax, 0 means unknown. AutoCad fails to open. When using the same version of ogr2ogr.exe for conversion without any parameters, the EntityHandle value in properties is not correctly obtained either(seems like the effect of default value of unset-fid option). However, it is in line with the syntax and AutoCad can open normally. The main code is as follows: |
It should be an additional option for the C# builds
The text was updated successfully, but these errors were encountered: