diff --git a/CMakeLists.txt b/CMakeLists.txt
index dcf6d9d4db..4cc99930cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -228,6 +228,12 @@ message(STATUS "XPRESS support: ${USE_XPRESS}")
if(BUILD_DOTNET)
option(UNIVERSAL_DOTNET_PACKAGE "Build a .Net multi OS Package" OFF)
message(STATUS ".Net: Create multiple os package: ${UNIVERSAL_DOTNET_PACKAGE}")
+
+ option(USE_DOTNET_TFM_31 "Use .Net Core 3.1 LTS support" ON)
+ message(STATUS ".Net: Use .Net Core 3.1 LTS support: ${USE_DOTNET_TFM_31}")
+
+ option(USE_DOTNET_TFM_60 "Use .Net 6.0 LTS support" ON)
+ message(STATUS ".Net: Use .Net 6.0 LTS support: ${USE_DOTNET_TFM_60}")
endif()
if(BUILD_JAVA)
diff --git a/cmake/dotnet.cmake b/cmake/dotnet.cmake
index d393f7e693..94af59ba55 100644
--- a/cmake/dotnet.cmake
+++ b/cmake/dotnet.cmake
@@ -30,6 +30,8 @@ endif()
# Needed by dotnet/CMakeLists.txt
set(DOTNET_PACKAGE Google.OrTools)
set(DOTNET_PACKAGES_DIR "${PROJECT_BINARY_DIR}/dotnet/packages")
+
+# see: https://docs.microsoft.com/en-us/dotnet/core/rid-catalog
if(APPLE)
set(RUNTIME_IDENTIFIER osx-x64)
elseif(UNIX)
@@ -44,6 +46,17 @@ message(STATUS ".Net runtime project: ${DOTNET_NATIVE_PROJECT}")
set(DOTNET_NATIVE_PROJECT_DIR ${PROJECT_BINARY_DIR}/dotnet/${DOTNET_NATIVE_PROJECT})
message(STATUS ".Net runtime project build path: ${DOTNET_NATIVE_PROJECT_DIR}")
+# see: https://docs.microsoft.com/en-us/dotnet/standard/frameworks
+if(USE_DOTNET_TFM_31 AND USE_DOTNET_TFM_60)
+ set(DOTNET_TFM "netcoreapp3.1;net6.0")
+elseif(USE_DOTNET_TFM_60)
+ set(DOTNET_TFM "net6.0")
+elseif(USE_DOTNET_TFM_31)
+ set(DOTNET_TFM "netcoreapp3.1")
+else()
+ message(FATAL_ERROR "No .Net SDK selected !")
+endif()
+
set(DOTNET_PROJECT ${DOTNET_PACKAGE})
message(STATUS ".Net project: ${DOTNET_PROJECT}")
set(DOTNET_PROJECT_DIR ${PROJECT_BINARY_DIR}/dotnet/${DOTNET_PROJECT})
@@ -368,10 +381,18 @@ function(add_dotnet_sample FILE_NAME)
WORKING_DIRECTORY ${DOTNET_SAMPLE_DIR})
if(BUILD_TESTING)
- add_test(
- NAME dotnet_${COMPONENT_NAME}_${SAMPLE_NAME}
- COMMAND ${DOTNET_EXECUTABLE} run --no-build --framework net6.0 -c Release
- WORKING_DIRECTORY ${DOTNET_SAMPLE_DIR})
+ if(USE_DOTNET_TFM_31)
+ add_test(
+ NAME dotnet_${COMPONENT_NAME}_${SAMPLE_NAME}
+ COMMAND ${DOTNET_EXECUTABLE} run --no-build --framework netcoreapp3.1 -c Release
+ WORKING_DIRECTORY ${DOTNET_SAMPLE_DIR})
+ endif()
+ if(USE_DOTNET_TFM_60)
+ add_test(
+ NAME dotnet_${COMPONENT_NAME}_${SAMPLE_NAME}
+ COMMAND ${DOTNET_EXECUTABLE} run --no-build --framework net6.0 -c Release
+ WORKING_DIRECTORY ${DOTNET_SAMPLE_DIR})
+ endif()
endif()
message(STATUS "Configuring sample ${FILE_NAME} done")
endfunction()
@@ -431,10 +452,18 @@ function(add_dotnet_example FILE_NAME)
WORKING_DIRECTORY ${DOTNET_EXAMPLE_DIR})
if(BUILD_TESTING)
- add_test(
- NAME dotnet_${COMPONENT_NAME}_${EXAMPLE_NAME}
- COMMAND ${DOTNET_EXECUTABLE} run --no-build --framework net6.0 -c Release
- WORKING_DIRECTORY ${DOTNET_EXAMPLE_DIR})
+ if(USE_DOTNET_TFM_31)
+ add_test(
+ NAME dotnet_${COMPONENT_NAME}_${EXAMPLE_NAME}
+ COMMAND ${DOTNET_EXECUTABLE} run --no-build --framework netcoreapp3.1 -c Release
+ WORKING_DIRECTORY ${DOTNET_EXAMPLE_DIR})
+ endif()
+ if(USE_DOTNET_TFM_60)
+ add_test(
+ NAME dotnet_${COMPONENT_NAME}_${EXAMPLE_NAME}
+ COMMAND ${DOTNET_EXECUTABLE} run --no-build --framework net6.0 -c Release
+ WORKING_DIRECTORY ${DOTNET_EXAMPLE_DIR})
+ endif()
endif()
message(STATUS "Configuring example ${FILE_NAME} done")
endfunction()
diff --git a/makefiles/Makefile.dotnet.mk b/makefiles/Makefile.dotnet.mk
index a37e607160..74ea0aa341 100644
--- a/makefiles/Makefile.dotnet.mk
+++ b/makefiles/Makefile.dotnet.mk
@@ -87,6 +87,8 @@ $$(TEMP_DOTNET_DIR)/$1/%/%.csproj: \
$$(SED) -e "s/@DOTNET_PACKAGES_DIR@/..\/..\/..\/$(BUILD_DIR)\/dotnet\/packages/" \
ortools$$Sdotnet$$SSample.csproj.in \
> $$(TEMP_DOTNET_DIR)$$S$1$$S$$*$$S$$*.csproj
+ $$(SED) -i -e 's/@DOTNET_TFM@/netcoreapp3.1;net6.0<\/TargetFrameworks>/' \
+ $$(TEMP_DOTNET_DIR)$$S$1$$S$$*$$S$$*.csproj
$$(SED) -i -e 's/@DOTNET_PROJECT@/$$(DOTNET_ORTOOLS_ASSEMBLY_NAME)/' \
$$(TEMP_DOTNET_DIR)$$S$1$$S$$*$$S$$*.csproj
$$(SED) -i -e 's/@SAMPLE_NAME@/$$*/' \
@@ -136,6 +138,8 @@ $$(TEMP_DOTNET_DIR)/$1/%/%.csproj: \
$$(SED) -e "s/@DOTNET_PACKAGES_DIR@/..\/..\/..\/$(BUILD_DIR)\/dotnet\/packages/" \
ortools$$Sdotnet$$SSample.csproj.in \
> $$(TEMP_DOTNET_DIR)$$S$1$$S$$*$$S$$*.csproj
+ $$(SED) -i -e 's/@DOTNET_TFM@/netcoreapp3.1;net6.0<\/TargetFrameworks>/' \
+ $$(TEMP_DOTNET_DIR)$$S$1$$S$$*$$S$$*.csproj
$$(SED) -i -e 's/@DOTNET_PROJECT@/$$(DOTNET_ORTOOLS_ASSEMBLY_NAME)/' \
$$(TEMP_DOTNET_DIR)$$S$1$$S$$*$$S$$*.csproj
$$(SED) -i -e 's/@SAMPLE_NAME@/$$*/' \
@@ -184,6 +188,8 @@ $(TEMP_DOTNET_DIR)/tests/%/%.csproj: \
$(SED) -e "s/@DOTNET_PACKAGES_DIR@/..\/..\/..\/$(BUILD_DIR)\/dotnet\/packages/" \
ortools$Sdotnet$STest.csproj.in \
> $(TEMP_DOTNET_DIR)$Stests$S$*$S$*.csproj
+ $(SED) -i -e 's/@DOTNET_TFM@/netcoreapp3.1;net6.0<\/TargetFrameworks>/' \
+ $(TEMP_DOTNET_DIR)$Stests$S$*$S$*.csproj
$(SED) -i -e 's/@DOTNET_PROJECT@/$(DOTNET_ORTOOLS_ASSEMBLY_NAME)/' \
$(TEMP_DOTNET_DIR)$Stests$S$*$S$*.csproj
$(SED) -i -e 's/@TEST_NAME@/$*/' \
@@ -483,6 +489,8 @@ $$(TEMP_DOTNET_DIR)/ortools_examples/examples/dotnet/%.csproj: \
$$(SED) -i -e 's/@PROJECT_VERSION_PATCH@/$$(GIT_REVISION)/' \
$$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
$(SED) -i -e 's/@DOTNET_PACKAGES_DIR@/./' \
+ $$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
+ $(SED) -i -e 's/@DOTNET_TFM@/netcoreapp3.1;net6.0<\/TargetFrameworks>/' \
$$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
$(SED) -i -e 's/@DOTNET_PROJECT@/$$(DOTNET_ORTOOLS_ASSEMBLY_NAME)/' \
$$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
@@ -512,6 +520,8 @@ $$(TEMP_DOTNET_DIR)/ortools_examples/examples/dotnet/%.csproj: \
$$(SED) -i -e 's/@PROJECT_VERSION_PATCH@/$$(GIT_REVISION)/' \
$$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
$(SED) -i -e 's/@DOTNET_PACKAGES_DIR@/./' \
+ $$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
+ $(SED) -i -e 's/@DOTNET_TFM@/netcoreapp3.1;net6.0<\/TargetFrameworks>/' \
$$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
$(SED) -i -e 's/@DOTNET_PROJECT@/$$(DOTNET_ORTOOLS_ASSEMBLY_NAME)/' \
$$(TEMP_DOTNET_DIR)$$Sortools_examples$$Sexamples$$Sdotnet$$S$$*.csproj
@@ -570,7 +580,7 @@ nuget_archive: dotnet | $(TEMP_DOTNET_DIR)
.PHONY: nuget_upload # Upload Nuget Package
nuget_upload: nuget_archive
- @echo Uploading Nuget package for "net6.0".
+ @echo Uploading Nuget package for "netcoreapp3.1;net6.0".
$(warning Not Implemented)
endif # HAS_DOTNET=ON
diff --git a/ortools/dotnet/Google.OrTools-full.csproj.in b/ortools/dotnet/Google.OrTools-full.csproj.in
index 6086f6071f..509a04f59a 100644
--- a/ortools/dotnet/Google.OrTools-full.csproj.in
+++ b/ortools/dotnet/Google.OrTools-full.csproj.in
@@ -2,7 +2,7 @@
Library
9.0
- netcoreapp3.1;net6.0
+ @DOTNET_TFM@
win-x64;osx-x64;linux-x64
true
@DOTNET_PROJECT@
diff --git a/ortools/dotnet/Google.OrTools-local.csproj.in b/ortools/dotnet/Google.OrTools-local.csproj.in
index 91359f336b..e9ec1bfeae 100644
--- a/ortools/dotnet/Google.OrTools-local.csproj.in
+++ b/ortools/dotnet/Google.OrTools-local.csproj.in
@@ -2,7 +2,7 @@
Library
9.0
- netcoreapp3.1;net6.0
+ @DOTNET_TFM@
@RUNTIME_IDENTIFIER@
true
@DOTNET_PROJECT@
diff --git a/ortools/dotnet/Google.OrTools.runtime.csproj.in b/ortools/dotnet/Google.OrTools.runtime.csproj.in
index d8f5893481..5cd5be36c0 100644
--- a/ortools/dotnet/Google.OrTools.runtime.csproj.in
+++ b/ortools/dotnet/Google.OrTools.runtime.csproj.in
@@ -1,7 +1,7 @@
Library
- netcoreapp3.1;net6.0
+ @DOTNET_TFM@
@RUNTIME_IDENTIFIER@
google-ortools-native
@PROJECT_VERSION@
diff --git a/ortools/dotnet/Sample.csproj.in b/ortools/dotnet/Sample.csproj.in
index ff67990948..d13eae05bc 100644
--- a/ortools/dotnet/Sample.csproj.in
+++ b/ortools/dotnet/Sample.csproj.in
@@ -2,7 +2,7 @@
Exe
8.0
- net6.0
+ @DOTNET_TFM@
false
false
diff --git a/ortools/dotnet/Test.csproj.in b/ortools/dotnet/Test.csproj.in
index 8f67632944..1b7459b59b 100644
--- a/ortools/dotnet/Test.csproj.in
+++ b/ortools/dotnet/Test.csproj.in
@@ -2,7 +2,7 @@
Exe
8.0
- netcoreapp3.1;net6.0
+ @DOTNET_TFM@
false
false