|
| 1 | +<!-- |
| 2 | +Add the native libraries from either a local build or a prebuilt native nuget package. |
| 3 | +
|
| 4 | +This has to be imported by the test project with the actual target platform/frameworks to work correctly as the common |
| 5 | +test project only targets net8 and netstandard2.0. |
| 6 | +--> |
| 7 | +<Project> |
| 8 | + <PropertyGroup> |
| 9 | + <!-- build host system --> |
| 10 | + <IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild> |
| 11 | + <IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild> |
| 12 | + <IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild> |
| 13 | + |
| 14 | + <!-- set for MAUI targets --> |
| 15 | + <IsWindowsTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">true</IsWindowsTarget> |
| 16 | + <IsAndroidTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IsAndroidTarget> |
| 17 | + <IsIOSTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</IsIOSTarget> |
| 18 | + <IsMacCatalystTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</IsMacCatalystTarget> |
| 19 | + |
| 20 | + <!-- |
| 21 | + Allow a pre-built ORT native nuget package (Microsoft.ML.OnnxRuntime.<version>.nupkg) to be used. |
| 22 | +
|
| 23 | + The test projects that include this file must be built from the command-line to enable using a prebuilt package. |
| 24 | + Current test projects: |
| 25 | + - Microsoft.ML.OnnxRuntime.Tests.NetCoreApp |
| 26 | + - Microsoft.ML.OnnxRuntime.Tests.MAUI |
| 27 | +
|
| 28 | + If running from the repo root the below is an example command. |
| 29 | + Note that '==' represents a double '-' which isn't allowed in an XML comment |
| 30 | + Properties can also be set via environment variables. |
| 31 | +
|
| 32 | + dotnet build csharp\test\Microsoft.ML.OnnxRuntime.Tests.MAUI\Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj |
| 33 | + ==property:UsePrebuiltNativePackage=true |
| 34 | + ==property:CurrentOnnxRuntimeVersion=1.19.2 |
| 35 | + ==source <path containing the Microsoft.ML.OnnxRuntime.<version>.nupkg> |
| 36 | + ==source https://api.nuget.org/v3/index.json |
| 37 | +
|
| 38 | + The <version> of the nupkg must match the value provided in CurrentOnnxRuntimeVersion. |
| 39 | +
|
| 40 | + The "==source" args are not required if a released Microsoft.ML.OnnxRuntime package is being used. |
| 41 | + If using a previous release you must ensure it is compatible with the entries in NativeMethods.shared.cs. |
| 42 | + If new bindings have been added recently you will get error when those are initialized if the native code is out |
| 43 | + of date and does not match. |
| 44 | + --> |
| 45 | + <UsePrebuiltNativePackage Condition="'$(UsePrebuiltNativePackage)' == ''">false</UsePrebuiltNativePackage> |
| 46 | + <CurrentOnnxRuntimeVersion Condition="'$(CurrentOnnxRuntimeVersion)' == ''">1.20.0-dev-20241007</CurrentOnnxRuntimeVersion> |
| 47 | + </PropertyGroup> |
| 48 | + |
| 49 | + <!-- debug output - makes finding/fixing any issues with the the conditions easy. --> |
| 50 | + <Target Name="DumpValues" BeforeTargets="PreBuildEvent"> |
| 51 | + <Message Text="NativeLibraryInclude: TargetPlatform='$(TargetPlatform)' TargetPlatformIdentifier='$(TargetPlatformIdentifier)' " /> |
| 52 | + <Message Text="TargetFramework='$(TargetFramework)' TargetFrameworkIdentifier='$(TargetFrameworkIdentifier)' " /> |
| 53 | + <Message Text="[MSBuild]::GetTargetPlatformIdentifier(TargetFramework)='$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))' " /> |
| 54 | + <Message Text="[MSBuild]::GetTargetFrameworkIdentifier(TargetFramework)='$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)'))' " /> |
| 55 | + <Message Text="IsWindowsBuild='$(IsWindowsBuild)' IsLinuxBuild='$(IsLinuxBuild)' IsMacOSBuild='$(IsMacOSBuild)'" /> |
| 56 | + <Message Text="IsWindowsTarget='$(IsWindowsTarget)' IsAndroidTarget='$(IsAndroidTarget)' IsIOSTarget='$(IsIOSTarget)' IsMacCatalystTarget='$(IsMacCatalystTarget)'" /> |
| 57 | + </Target> |
| 58 | + |
| 59 | + <ItemGroup Condition="'$(UsePrebuiltNativePackage)' == 'true'"> |
| 60 | + <!-- Use the prebuilt package --> |
| 61 | + <PackageReference Include="Microsoft.ML.OnnxRuntime" Version="$(CurrentOnnxRuntimeVersion)" /> |
| 62 | + </ItemGroup> |
| 63 | + |
| 64 | + <!-- 'Choose' so we don't need the UsePrebuiltNativePackage condition on all the PropertyGroup/ItemGroup elements --> |
| 65 | + <Choose> |
| 66 | + <When Condition="'$(UsePrebuiltNativePackage)' != 'true'"> |
| 67 | + <PropertyGroup Condition="'$(IsWindowsBuild)'=='true' OR '$(IsWindowsTarget)'=='true'"> |
| 68 | + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Windows</OnnxRuntimeBuildDirectory> |
| 69 | + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir> |
| 70 | + </PropertyGroup> |
| 71 | + |
| 72 | + <PropertyGroup Condition="'$(IsLinuxBuild)'=='true'"> |
| 73 | + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Linux</OnnxRuntimeBuildDirectory> |
| 74 | + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> |
| 75 | + </PropertyGroup> |
| 76 | + |
| 77 | + <PropertyGroup Condition="'$(IsMacOSBuild)'=='true'"> |
| 78 | + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\MacOS</OnnxRuntimeBuildDirectory> |
| 79 | + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> |
| 80 | + </PropertyGroup> |
| 81 | + |
| 82 | + <PropertyGroup Condition="'$(IsAndroidTarget)' == 'true'"> |
| 83 | + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Android</OnnxRuntimeBuildDirectory> |
| 84 | + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> |
| 85 | + </PropertyGroup> |
| 86 | + |
| 87 | + <PropertyGroup Condition="'$(IsIOSTarget)' == 'true'"> |
| 88 | + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\iOS</OnnxRuntimeBuildDirectory> |
| 89 | + <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform> |
| 90 | + <PlatformLower>$(Platform.ToLower())</PlatformLower> |
| 91 | + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)-$(PlatformLower)</NativeBuildOutputDir> |
| 92 | + </PropertyGroup> |
| 93 | + |
| 94 | + <PropertyGroup Condition="'$(IsMacCatalystTarget)' == 'true'"> |
| 95 | + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\macOS</OnnxRuntimeBuildDirectory> |
| 96 | + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> |
| 97 | + </PropertyGroup> |
| 98 | + |
| 99 | + <ItemGroup Condition="'$(IsWindowsBuild)' == 'true' OR '$(IsWindowsTarget)'=='true'"> |
| 100 | + <None Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.dll')" |
| 101 | + Include="$(NativeBuildOutputDir)\*.dll;$(NativeBuildOutputDir)\*.pdb"> |
| 102 | + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
| 103 | + <Visible>true</Visible> |
| 104 | + </None> |
| 105 | + </ItemGroup> |
| 106 | + |
| 107 | + <ItemGroup Condition="'$(IsLinuxBuild)' == 'true'"> |
| 108 | + <None Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')" |
| 109 | + Include="$(NativeBuildOutputDir)\libonnxruntime.so"> |
| 110 | + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
| 111 | + <Visible>false</Visible> |
| 112 | + </None> |
| 113 | + </ItemGroup> |
| 114 | + |
| 115 | + <ItemGroup Condition="'$(IsMacOSBuild)' == 'true'"> |
| 116 | + <None Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" |
| 117 | + Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> |
| 118 | + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> |
| 119 | + <Visible>false</Visible> |
| 120 | + </None> |
| 121 | + </ItemGroup> |
| 122 | + |
| 123 | + <ItemGroup Condition="'$(IsAndroidTarget)' == 'true'"> |
| 124 | + <AndroidNativeLibrary Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')" |
| 125 | + Include="$(NativeBuildOutputDir)\libonnxruntime.so"> |
| 126 | + <Link>libs\libonnxruntime.so</Link> |
| 127 | + </AndroidNativeLibrary> |
| 128 | + </ItemGroup> |
| 129 | + |
| 130 | + <ItemGroup Condition="'$(IsIOSTarget)' == 'true'"> |
| 131 | + <NativeReference Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" |
| 132 | + Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> |
| 133 | + <Link>libs\libonnxruntime.dylib</Link> |
| 134 | + <Kind>Dynamic</Kind> |
| 135 | + <ForceLoad>True</ForceLoad> |
| 136 | + <IsCxx>True</IsCxx> |
| 137 | + </NativeReference> |
| 138 | + </ItemGroup> |
| 139 | + |
| 140 | + <ItemGroup Condition="'$(IsMacCatalystTarget)' == 'true'"> |
| 141 | + <NativeReference Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" |
| 142 | + Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> |
| 143 | + <Link>libs\libonnxruntime.dylib</Link> |
| 144 | + <Kind>Dynamic</Kind> |
| 145 | + <ForceLoad>True</ForceLoad> |
| 146 | + <IsCxx>True</IsCxx> |
| 147 | + </NativeReference> |
| 148 | + </ItemGroup> |
| 149 | + </When> |
| 150 | + </Choose> |
| 151 | + |
| 152 | + <!-- Property debug output. --> |
| 153 | + <PropertyGroup> |
| 154 | + <!-- local builds--> |
| 155 | + <HaveOrtDll>false</HaveOrtDll> |
| 156 | + <HaveOrtDll Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.dll')">true</HaveOrtDll> |
| 157 | + <HaveOrtSo>false</HaveOrtSo> |
| 158 | + <HaveOrtSo Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')">true</HaveOrtSo> |
| 159 | + <HaveOrtDylib>false</HaveOrtDylib> |
| 160 | + <HaveOrtDylib Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')">true</HaveOrtDylib> |
| 161 | + </PropertyGroup> |
| 162 | + |
| 163 | + <Target Name="DumpLocalBuild" BeforeTargets="PreBuildEvent"> |
| 164 | + <Message Text="Prebuilt runtime=$(UsePrebuiltNativePackage)" /> |
| 165 | + <Message Text="NativeBuildOutputDir=$(NativeBuildOutputDir)" /> |
| 166 | + <Message Text="onnxruntime.dll from local build=$(HaveOrtDll)" /> |
| 167 | + <Message Text="libonnxruntime.so from local build=$(HaveOrtSo)" /> |
| 168 | + <Message Text="libonnxruntime.dylib from local build=$(HaveOrtDylib)" /> |
| 169 | + </Target> |
| 170 | + |
| 171 | +</Project> |
0 commit comments