From 4377ff4a1a1d0ec65a811669abcf5f0508007469 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Tue, 9 Jun 2020 09:08:19 -0700 Subject: [PATCH] Enable .NET Core 2.0 and .NET Framework 4.6.1 in Microsoft.AI.MachineLearning NuGet package (#4125) * add project to download cswinrt and build winrt c# interop dll * Add to nuget package * reverse if check * run generation before core compile * add generated files to compile * update .net package to binplace native libs * add props to .netstandard2.0 folder * auto binplace ml native binaries * force 'Any CPU' platform build * Fix anycpu and platform targets * fix flake errors * fix variable order * fix flake pep8 errors, semicolon Co-authored-by: Sheil Kumar --- csharp/OnnxRuntime.CSharp.proj | 2 +- .../.gitignore | 1 + ...icrosoft.AI.MachineLearning.Interop.csproj | 48 ++++++++++++++ .../Microsoft.AI.MachineLearning.targets | 32 ++++++++++ ...osoft.AI.MachineLearning.Rules.Project.xml | 0 .../Microsoft.AI.MachineLearning.props | 0 .../Microsoft.AI.MachineLearning.targets | 0 .../templates/windowsai-nuget-build.yml | 4 ++ .../nuget/generate_nuspec_for_native_nuget.py | 64 +++++++++++++------ 9 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 csharp/src/Microsoft.AI.MachineLearning.Interop/.gitignore create mode 100644 csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.Interop.csproj create mode 100644 csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets rename csharp/src/{Microsoft.ML.OnnxRuntime => Microsoft.AI.MachineLearning}/Microsoft.AI.MachineLearning.Rules.Project.xml (100%) rename csharp/src/{Microsoft.ML.OnnxRuntime => Microsoft.AI.MachineLearning}/Microsoft.AI.MachineLearning.props (100%) rename csharp/src/{Microsoft.ML.OnnxRuntime => Microsoft.AI.MachineLearning}/Microsoft.AI.MachineLearning.targets (100%) diff --git a/csharp/OnnxRuntime.CSharp.proj b/csharp/OnnxRuntime.CSharp.proj index 01ed2eb326..a5058e9c07 100644 --- a/csharp/OnnxRuntime.CSharp.proj +++ b/csharp/OnnxRuntime.CSharp.proj @@ -138,5 +138,5 @@ CMake creates a target to this project - + diff --git a/csharp/src/Microsoft.AI.MachineLearning.Interop/.gitignore b/csharp/src/Microsoft.AI.MachineLearning.Interop/.gitignore new file mode 100644 index 0000000000..f128932de7 --- /dev/null +++ b/csharp/src/Microsoft.AI.MachineLearning.Interop/.gitignore @@ -0,0 +1 @@ +Generated Files \ No newline at end of file diff --git a/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.Interop.csproj b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.Interop.csproj new file mode 100644 index 0000000000..0eae08f67e --- /dev/null +++ b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.Interop.csproj @@ -0,0 +1,48 @@ + + + + Microsoft.AI.MachineLearning.Interop + netstandard2.0 + true + + Any CPU + Debug + + ..\..\..\build\Windows + $(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration) + $(BuildOutputDir)\Microsoft.AI.MachineLearning.Interop + $(WindowsAIInteropOutputDir) + + + + + + + + + + + + + + + + + + + + + + $(CsWinRTPath)cswinrt.exe -verbose -in local -in @(WindowsAIsWinMDs->'"%(FullPath)"', ' ') -out "$(ProjectDir)Generated Files" -include Microsoft.AI.MachineLearning + + + + + + + + + + + + \ No newline at end of file diff --git a/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets new file mode 100644 index 0000000000..0c38e34e04 --- /dev/null +++ b/csharp/src/Microsoft.AI.MachineLearning.Interop/Microsoft.AI.MachineLearning.targets @@ -0,0 +1,32 @@ + + + + x64 + x86 + $(PlatformTarget) + + + + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\Microsoft.AI.MachineLearning.dll + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\onnxruntime.dll + $(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\directml.dll + + + + $(WindowsAIBinary);$(OnnxRuntimeBinary);$(DirectMLBinary) + + + $(WindowsAIBinary);$(OnnxRuntimeBinary);$(DirectMLBinary) + + + $(WindowsAIBinary);$(OnnxRuntimeBinary) + + + + + Binplacing WindowsAI binaries: {0} and {1}. + + + + + diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.Rules.Project.xml b/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.Rules.Project.xml similarity index 100% rename from csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.Rules.Project.xml rename to csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.Rules.Project.xml diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.props b/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.props similarity index 100% rename from csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.props rename to csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.props diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.targets b/csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.targets similarity index 100% rename from csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.AI.MachineLearning.targets rename to csharp/src/Microsoft.AI.MachineLearning/Microsoft.AI.MachineLearning.targets diff --git a/tools/ci_build/github/azure-pipelines/templates/windowsai-nuget-build.yml b/tools/ci_build/github/azure-pipelines/templates/windowsai-nuget-build.yml index c96efd52c5..6a1d041f58 100644 --- a/tools/ci_build/github/azure-pipelines/templates/windowsai-nuget-build.yml +++ b/tools/ci_build/github/azure-pipelines/templates/windowsai-nuget-build.yml @@ -135,6 +135,10 @@ steps: arguments: 'x64' modifyEnvironment: true + - script: msbuild Microsoft.AI.MachineLearning.Interop.csproj /p:Configuration=RelWithDebInfo /p:Platform="Any CPU" /p:OnnxRuntimeBuildDirectory=$(Build.BinariesDirectory) -restore + workingDirectory: '$(Build.SourcesDirectory)\csharp\src\Microsoft.AI.MachineLearning.Interop' + displayName: 'Build Microsoft.AI.MachineLearning.Interop.dll' + # Esrp signing - template: win-esrp-dll.yml parameters: diff --git a/tools/nuget/generate_nuspec_for_native_nuget.py b/tools/nuget/generate_nuspec_for_native_nuget.py index dc52591343..7164db22d6 100644 --- a/tools/nuget/generate_nuspec_for_native_nuget.py +++ b/tools/nuget/generate_nuspec_for_native_nuget.py @@ -71,7 +71,24 @@ def generate_repo_url(list, repo_url, commit_id): def generate_dependencies(list, package_name, version): - if (package_name != 'Microsoft.AI.MachineLearning'): + if (package_name == 'Microsoft.AI.MachineLearning'): + list.append('') + + # Support .Net Core + list.append('') + list.append('') + list.append('') + # Support .Net Standard + list.append('') + list.append('') + list.append('') + # Support .Net Framework + list.append('') + list.append('') + list.append('') + + list.append('') + else: list.append('') # Support .Net Core list.append('') @@ -167,7 +184,6 @@ def generate_files(list, args): '" target="build\\native\\include" />') if includes_winml: - mlop_path = 'onnxruntime\\core\\providers\\dml\\dmlexecutionprovider\\inc\\mloperatorauthor.h' # Add microsoft.ai.machinelearning headers files_list.append('') + # Add custom operator headers + mlop_path = 'onnxruntime\\core\\providers\\dml\\dmlexecutionprovider\\inc\\mloperatorauthor.h' + files_list.append('') # Process microsoft.ai.machinelearning.winmd files_list.append('') - # Add custom operator headers - files_list.append('') + interop_dll = 'Microsoft.AI.MachineLearning.Interop\\netstandard2.0\\Microsoft.AI.MachineLearning.Interop.dll' + files_list.append('') + interop_pdb = 'Microsoft.AI.MachineLearning.Interop\\netstandard2.0\\Microsoft.AI.MachineLearning.Interop.pdb' + files_list.append('') # Process runtimes # Process onnxruntime import lib, dll, and pdb @@ -254,18 +276,24 @@ def generate_files(list, args): # Process props and targets files if is_windowsai_package: - # Process props file - windowsai_props = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', - 'Microsoft.AI.MachineLearning.props') - files_list.append('') - # Process targets files - windowsai_targets = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', - 'Microsoft.AI.MachineLearning.targets') - files_list.append('') - # Process rules files - windowsai_rules = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime', - 'Microsoft.AI.MachineLearning.Rules.Project.xml') - files_list.append('') + windowsai_src = 'Microsoft.AI.MachineLearning' + # Process native props + windowsai_props = 'Microsoft.AI.MachineLearning.props' + windowsai_native_props = os.path.join(args.sources_path, 'csharp', 'src', windowsai_src, windowsai_props) + files_list.append('') + # Process native targets + windowsai_targets = 'Microsoft.AI.MachineLearning.targets' + windowsai_native_targets = os.path.join(args.sources_path, 'csharp', 'src', windowsai_src, windowsai_targets) + files_list.append('') + # Process native rules + windowsai_rules = 'Microsoft.AI.MachineLearning.Rules.Project.xml' + windowsai_native_rules = os.path.join(args.sources_path, 'csharp', 'src', windowsai_src, windowsai_rules) + files_list.append('') + # Process .net standard 2.0 targets + interop_src = 'Microsoft.AI.MachineLearning.Interop' + interop_targets = 'Microsoft.AI.MachineLearning.targets' + windowsai_net20_targets = os.path.join(args.sources_path, 'csharp', 'src', interop_src, interop_targets) + files_list.append('') if is_cpu_package or is_cuda_gpu_package or is_dml_package or is_mklml_package: # Process props file