mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-24 19:43:35 +00:00
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 <sheilk@microsoft.com>
This commit is contained in:
parent
28d12dc4f0
commit
4377ff4a1a
9 changed files with 132 additions and 19 deletions
|
|
@ -138,5 +138,5 @@ CMake creates a target to this project
|
|||
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
|
||||
</Exec>
|
||||
</Target>
|
||||
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
1
csharp/src/Microsoft.AI.MachineLearning.Interop/.gitignore
vendored
Normal file
1
csharp/src/Microsoft.AI.MachineLearning.Interop/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
Generated Files
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<ProjectName>Microsoft.AI.MachineLearning.Interop</ProjectName>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
||||
<Platform>Any CPU</Platform>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
|
||||
<OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">..\..\..\build\Windows</OnnxRuntimeBuildDirectory>
|
||||
<BuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</BuildOutputDir>
|
||||
<WindowsAIInteropOutputDir>$(BuildOutputDir)\Microsoft.AI.MachineLearning.Interop</WindowsAIInteropOutputDir>
|
||||
<OutputPath>$(WindowsAIInteropOutputDir)</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="0.1.0-prerelease.200512.7" targetFramework="net46" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.NET" Version="10.0.18362.3-preview" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Generated Files\" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="GenerateProjection" BeforeTargets="DispatchToInnerBuilds;Build;CoreCompile">
|
||||
<ConvertToAbsolutePath Paths="$(OnnxRuntimeBuildDirectory)">
|
||||
<Output TaskParameter="AbsolutePaths" PropertyName="OnnxRuntimeBuildDirectoryAbs"/>
|
||||
</ConvertToAbsolutePath>
|
||||
|
||||
<ItemGroup>
|
||||
<WindowsAIsWinMDs Include="$(OnnxRuntimeBuildDirectoryAbs)\$(Configuration)\Microsoft.AI.MachineLearning.winmd" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<CsWinRTCommand>$(CsWinRTPath)cswinrt.exe -verbose -in local -in @(WindowsAIsWinMDs->'"%(FullPath)"', ' ') -out "$(ProjectDir)Generated Files" -include Microsoft.AI.MachineLearning</CsWinRTCommand>
|
||||
</PropertyGroup>
|
||||
|
||||
<Message Text="Generating $(ProjectName) CS projection sources with command:"/>
|
||||
<Message Text="$(CsWinRTCommand)"/>
|
||||
<Exec Command="$(CsWinRTCommand)" />
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="$(ProjectDir)Generated Files/*.cs" Exclude="@(Compile)" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<WindowsAI-Platform Condition="'$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')">x64</WindowsAI-Platform>
|
||||
<WindowsAI-Platform Condition="'$(PlatformTarget)' == 'x86' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' == 'true')">x86</WindowsAI-Platform>
|
||||
<WindowsAI-Platform Condition="'$(WindowsAI-Platform)' == ''">$(PlatformTarget)</WindowsAI-Platform>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<WindowsAIBinary>$(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\Microsoft.AI.MachineLearning.dll</WindowsAIBinary>
|
||||
<OnnxRuntimeBinary>$(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\onnxruntime.dll</OnnxRuntimeBinary>
|
||||
<DirectMLBinary>$(MSBuildThisFileDirectory)..\..\runtimes\win-$(WindowsAI-Platform)\native\directml.dll</DirectMLBinary>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<MLBinaries>$(WindowsAIBinary);$(OnnxRuntimeBinary);$(DirectMLBinary)</MLBinaries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsAI-Platform)' == x64 OR '$(WindowsAI-Platform)' == x86">
|
||||
<MLBinaries>$(WindowsAIBinary);$(OnnxRuntimeBinary);$(DirectMLBinary)</MLBinaries>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsAI-Platform)' == arm OR '$(WindowsAI-Platform)' == arm64">
|
||||
<MLBinaries>$(WindowsAIBinary);$(OnnxRuntimeBinary)</MLBinaries>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="CopyMLBinaries" BeforeTargets="CoreBuild">
|
||||
<PropertyGroup>
|
||||
<WindowsAIBinplaceMessage>Binplacing WindowsAI binaries: {0} and {1}.</WindowsAIBinplaceMessage>
|
||||
</PropertyGroup>
|
||||
<Message Text="$([System.String]::Format('$(WindowsAIBinplaceMessage)', '$(WindowsAIBinary)', '$(OnnxRuntimeBinary)'))" />
|
||||
<Copy SkipUnchangedFiles="True" SourceFiles="$(MLBinaries)" DestinationFolder="$(OutDir)" />
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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('<dependencies>')
|
||||
|
||||
# Support .Net Core
|
||||
list.append('<group targetFramework="NETCOREAPP">')
|
||||
list.append('<dependency id="Microsoft.Windows.SDK.NET"' + ' version="10.0.18362.3-preview"/>')
|
||||
list.append('</group>')
|
||||
# Support .Net Standard
|
||||
list.append('<group targetFramework="NETSTANDARD">')
|
||||
list.append('<dependency id="Microsoft.Windows.SDK.NET"' + ' version="10.0.18362.3-preview"/>')
|
||||
list.append('</group>')
|
||||
# Support .Net Framework
|
||||
list.append('<group targetFramework="NETFRAMEWORK">')
|
||||
list.append('<dependency id="Microsoft.Windows.SDK.NET"' + ' version="10.0.18362.3-preview"/>')
|
||||
list.append('</group>')
|
||||
|
||||
list.append('</dependencies>')
|
||||
else:
|
||||
list.append('<dependencies>')
|
||||
# Support .Net Core
|
||||
list.append('<group targetFramework="NETCOREAPP">')
|
||||
|
|
@ -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('<file src=' + '"' + os.path.join(args.ort_build_path, args.build_config,
|
||||
'microsoft.ai.machinelearning.h') +
|
||||
|
|
@ -178,14 +194,20 @@ def generate_files(list, args):
|
|||
files_list.append('<file src=' + '"' + os.path.join(args.ort_build_path, args.build_config,
|
||||
'microsoft.ai.machinelearning.native.h') +
|
||||
'" target="build\\native\\include\\Microsoft.AI.MachineLearning.Native.h" />')
|
||||
# Add custom operator headers
|
||||
mlop_path = 'onnxruntime\\core\\providers\\dml\\dmlexecutionprovider\\inc\\mloperatorauthor.h'
|
||||
files_list.append('<file src=' + '"' + os.path.join(args.sources_path, mlop_path) +
|
||||
'" target="build\\native\\include" />')
|
||||
# Process microsoft.ai.machinelearning.winmd
|
||||
files_list.append('<file src=' + '"' + os.path.join(args.ort_build_path, args.build_config,
|
||||
'microsoft.ai.machinelearning.winmd') +
|
||||
'" target="lib\\uap10.0\\Microsoft.AI.MachineLearning.winmd" />')
|
||||
# Add custom operator headers
|
||||
files_list.append('<file src=' + '"' +
|
||||
os.path.join(args.sources_path, mlop_path) +
|
||||
'" target="build\\native\\include" />')
|
||||
interop_dll = 'Microsoft.AI.MachineLearning.Interop\\netstandard2.0\\Microsoft.AI.MachineLearning.Interop.dll'
|
||||
files_list.append('<file src=' + '"' + os.path.join(args.native_build_path, interop_dll) +
|
||||
'" target="lib\\netstandard2.0\\Microsoft.AI.MachineLearning.Interop.dll" />')
|
||||
interop_pdb = 'Microsoft.AI.MachineLearning.Interop\\netstandard2.0\\Microsoft.AI.MachineLearning.Interop.pdb'
|
||||
files_list.append('<file src=' + '"' + os.path.join(args.native_build_path, interop_pdb) +
|
||||
'" target="lib\\netstandard2.0\\Microsoft.AI.MachineLearning.Interop.pdb" />')
|
||||
|
||||
# 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('<file src=' + '"' + windowsai_props + '" target="build\\native" />')
|
||||
# Process targets files
|
||||
windowsai_targets = os.path.join(args.sources_path, 'csharp', 'src', 'Microsoft.ML.OnnxRuntime',
|
||||
'Microsoft.AI.MachineLearning.targets')
|
||||
files_list.append('<file src=' + '"' + windowsai_targets + '" target="build\\native" />')
|
||||
# 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('<file src=' + '"' + windowsai_rules + '" target="build\\native" />')
|
||||
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('<file src=' + '"' + windowsai_native_props + '" target="build\\native" />')
|
||||
# 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('<file src=' + '"' + windowsai_native_targets + '" target="build\\native" />')
|
||||
# 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('<file src=' + '"' + windowsai_native_rules + '" target="build\\native" />')
|
||||
# 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('<file src=' + '"' + windowsai_net20_targets + '" target="build\\netstandard2.0" />')
|
||||
|
||||
if is_cpu_package or is_cuda_gpu_package or is_dml_package or is_mklml_package:
|
||||
# Process props file
|
||||
|
|
|
|||
Loading…
Reference in a new issue