OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.91k stars 2.55k forks source link

Offline build or CSharp bindings (ie not accessing nuget) #11264

Open Thorwyn101 opened 1 day ago

Thorwyn101 commented 1 day ago

What is the bug?

I want to build GDAL including CSharp bindings without internet connection. The GDAL-repository (tag 3.10.0) is checked-out and all dependencies are downloaded beforehand. The CMake build fails with: CUSTOMBUILD : error : NU1301: Unable to load the service index for source https://api.nuget.org/v3/index.json.

Package 'OSGeo.OSR' is compatible with all the specified frameworks in project '<PATH>/gdal_build/swig/csharp/ogr/ogr_csharp.csproj'.

CUSTOMBUILD : error : Value cannot be null. (Parameter 'version')

Steps to reproduce the issue

cmake.exe -S gdal -B gdal_build -DCMAKE_INSTALL_PREFIX=gdal_install -DCMAKE_TOOLCHAIN_FILE=<vcpkg>/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows -DCMAKE_BUILD_TYPE=Release -DSWIG_EXECUTABLE=<swig_path>/swig.exe -DSWIG_DIR=<swig_path> -DBUILD_TESTING=OFF -DGDAL_CSHARP_ONLY=OFF -DBUILD_CSHARP_BINDINGS=ON -DCSHARP_MONO=OFF -DCSHARP_LIBRARY_VERSION=net8.0-windows -DCSHARP_APPLICATION_VERSION=net8.0-windows

cmake.exe --build gdal_build --target install

Versions and provenance

GDAL: 3.10.0

swig: 4.1.1

Microsoft Visual Studio 2022

Windows 11

installed vcpkg packages:

Additional context

No response

rouault commented 1 day ago

@runette maybe you have some clues?

Thorwyn101 commented 1 day ago

The custom build step in OSGeo.OSR.vcxproj fails at this line: "C:\Program Files\dotnet\dotnet.exe" add <PATH>/gdal_build/swig/csharp/osr/osr_csharp.csproj package --version 3.10.0-dev OSGeo.GDAL.Core

runette commented 1 day ago

Yes.

The C# build process uses NuGET and NuGET defaults to accessing https://api.nuget.org/v3/index.json to get a list of packages.

From memory - we are only using it to reload local packages - so there may be a way of turning the default off. I can look into that bu it may be a day or two.

runette commented 1 day ago

It is a little bit more complicated. I have NOT been able to test this - since I do not have a development environment at the moment.

You SHOULD be able to build the libraries standalone, however the sample applications have .NET dependencies and will probably fail. That is probably ok for you - the sample apps are mostly only for testing - however there is no compile switch to turn the sample apps off.

If you run this command before building GDAL - the libraries SHOULD build but the apps should all error out at the dotnet build stage.

nuget sources Disable -Name "nuget.org"

or the equivalent dotnet command

dotnet nuget disable source "nuget.org"

As an alternative - you could try the following:

1 Run the above command 2 Build GDAL WITHOUT the C# bindings 3 Build the target csharp-bindings

That will only build the libraries and not the apps - I am just not sure if the second build will correctly find the gdal binaries.

runette commented 1 day ago

Additional NOTE - Since you have BUILD_TESTING=OFF - I do not think that it will build the sample apps - so I would try the first method.

Thorwyn101 commented 12 hours ago

I had a look at the CMake files and found this piece in FindDotnet.cmake:

IF(WIN32)
   FIND_PROGRAM(NUGET_EXE nuget PATHS ${CMAKE_BINARY_DIR}/tools)
   IF(NUGET_EXE)
       MESSAGE("-- Found nuget: ${NUGET_EXE}")
   ELSE()
        SET(NUGET_EXE ${CMAKE_BINARY_DIR}/tools/nuget.exe)
        MESSAGE("-- Downloading nuget...")
        FILE(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe ${NUGET_EXE})
        MESSAGE("nuget.exe downloaded and saved to ${NUGET_EXE}")
   ENDIF()
ENDIF()

If it can not find nuget.exe, it downloads the file. But without internet connection this file gets created but is empty!

So for me the solution is to provide nuget.exe:

-DNUGET_EXE=<PATH TO NUGET.EXE>

Thorwyn101 commented 11 hours ago
dotnet nuget disable source "nuget.org"

Does work too. Thanks :)

runette commented 8 hours ago

I had a look at the CMake files and found this piece in FindDotnet.cmake:

IF(WIN32)
   FIND_PROGRAM(NUGET_EXE nuget PATHS ${CMAKE_BINARY_DIR}/tools)
   IF(NUGET_EXE)
       MESSAGE("-- Found nuget: ${NUGET_EXE}")
   ELSE()
        SET(NUGET_EXE ${CMAKE_BINARY_DIR}/tools/nuget.exe)
        MESSAGE("-- Downloading nuget...")
        FILE(DOWNLOAD https://dist.nuget.org/win-x86-commandline/latest/nuget.exe ${NUGET_EXE})
        MESSAGE("nuget.exe downloaded and saved to ${NUGET_EXE}")
   ENDIF()
ENDIF()

If it can not find nuget.exe, it downloads the file. But without internet connection this file gets created but is empty!

So for me the solution is to provide nuget.exe:

-DNUGET_EXE=<PATH TO NUGET.EXE>

I will look at that