THRIFT-5796 Indicate target environment via #if check
Client: netstd
Patch: Jens Geyer
diff --git a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
index 01ba442..be4da42 100644
--- a/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_netstd_generator.cc
@@ -202,6 +202,20 @@
 
 void t_netstd_generator::pragmas_and_directives(ostream& out)
 {
+    if( target_net_version >= 8) {
+        out << "// targeting net 8" << '\n';
+        out << "#if( !NET8_0_OR_GREATER)" << '\n';
+    } else if( target_net_version >= 6) {
+        out << "// targeting net 6" << '\n';
+        out << "#if( NET8_0_OR_GREATER || !NET6_0_OR_GREATER)" << '\n';
+    } else {
+        out << "// targeting netstandard 2.x" << '\n';
+        out << "#if(! NETSTANDARD2_0_OR_GREATER)" << '\n';
+    }
+    out << "#error Unexpected target platform. See 'thrift --help' for details." << '\n';
+    out << "#endif" << '\n';
+    out << '\n';
+
     if( target_net_version >= 6) {
       out << "// Thrift code generated for net" << target_net_version << '\n';
       out << "#nullable enable                 // requires C# 8.0" << '\n';
diff --git a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj
index 7922423..7e5f790 100644
--- a/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj
+++ b/lib/netstd/Tests/Thrift.PublicInterfaces.Compile.Tests/Thrift.PublicInterfaces.Compile.Tests.csproj
@@ -82,8 +82,10 @@
     <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./Thrift5382.thrift" />
     <Exec Command="$(PathToThrift) -gen netstd:wcf,union,serial,net8 -r ./Thrift5795.thrift" />
     <!-- special options (see ticket) -->
+    <!-- wil be reacivated later
     <Exec Command="$(PathToThrift) -gen netstd                       -r ./Thrift5794-netstd.thrift" />
     <Exec Command="$(PathToThrift) -gen netstd:net6                  -r ./Thrift5794-net6.thrift" />
+    -->
     <Exec Command="$(PathToThrift) -gen netstd:net8                  -r ./Thrift5794-net8.thrift" />
   </Target>
 
diff --git a/tutorial/netstd/Interfaces/Interfaces.csproj b/tutorial/netstd/Interfaces/Interfaces.csproj
index 73a0935..b0de842 100644
--- a/tutorial/netstd/Interfaces/Interfaces.csproj
+++ b/tutorial/netstd/Interfaces/Interfaces.csproj
@@ -41,8 +41,8 @@
     <Exec Condition="'$(OS)' == 'Windows_NT'" Command="where thrift" ConsoleToMSBuild="true">
       <Output TaskParameter="ConsoleOutput" PropertyName="PathToThrift" />
     </Exec>
-    <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../tutorial.thrift" />
-    <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../tutorial.thrift" />
-    <Exec Condition="Exists('./../../../compiler/cpp/thrift')" Command="./../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net6 -r ./../../tutorial.thrift" />
+    <Exec Condition="Exists('$(PathToThrift)')" Command="$(PathToThrift) -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../tutorial.thrift" />
+    <Exec Condition="Exists('thrift')" Command="thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../tutorial.thrift" />
+    <Exec Condition="Exists('./../../../compiler/cpp/thrift')" Command="./../../../compiler/cpp/thrift -out $(ProjectDir) -gen netstd:wcf,union,serial,net8 -r ./../../tutorial.thrift" />
   </Target>
 </Project>