diff --git a/csharp/OnnxRuntime.CSharp.proj b/csharp/OnnxRuntime.CSharp.proj index 95207d158affe..6779fd60bcd0a 100644 --- a/csharp/OnnxRuntime.CSharp.proj +++ b/csharp/OnnxRuntime.CSharp.proj @@ -64,13 +64,6 @@ CMake creates a target to this project <Error Text="Building via this file is not supported. Please build using the appropriate .sln file in this directory." /> </Target> - <Target Name="RunTest"> - <Message Importance="High" Text="Running CSharp tests..." /> - <Exec Command="$(DotNetExe) test test\Microsoft.ML.OnnxRuntime.Tests\Microsoft.ML.OnnxRuntime.Tests.csproj -c $(Configuration) --no-build --blame -v n" ConsoleToMSBuild="true"> - <Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" /> - </Exec> - </Target> - <Target Name="ObtainPackageVersion" BeforeTargets="Build;CreatePackage;CreateWindowsAIPackage;CreateNativePackage"> <ReadLinesFromFile File="..\VERSION_NUMBER"> <Output TaskParameter="Lines" ItemName="MajorVersionNumber"/> @@ -153,7 +146,7 @@ CMake creates a target to this project <!-- Create Microsoft.ML.OnnxRuntime.Managed with the C# bindings using the C# project --> <Message Condition="'$(IsPlatformSpecificSubPackage)'!='True'" Importance="High" Text="Creating Microsoft.ML.OnnxRuntime.Managed nuget package..." /> <MSBuild Condition="'$(IsPlatformSpecificSubPackage)'!='True'" Projects="src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" - Targets="CopyMiscFiles;Pack" + Targets="RenameFilesToPack;Pack" Properties="NoBuild=true;Platform=AnyCPU;PackageVersion=$(PackageVersion);OrtPackageId=$(OrtPackageId);IncludeMobileTargets=$(IncludeMobileTargets)"/> <MSBuild Projects ="$(MSBuildProjectFullPath)" diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj index 078c7252c897e..63131d05c03d5 100644 --- a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj +++ b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj @@ -31,6 +31,33 @@ <TargetFrameworks>$(BaseTargets);$(MobileTargets)</TargetFrameworks> </PropertyGroup> + <PropertyGroup> + <!-- Build host --> + <IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild> + <IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild> + <IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild> + + <!-- $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) gives better results for MAUI builds than + $(TargetPlatformIdentifier). See https://github.com/dotnet/msbuild/issues/7359 + Note there are slight differences in casing (e.g. macos vs macOS), so if we ever + change to use $(TargetPlatformIdentifier) we need to adjust for that. + --> + <IsWindowsTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">true</IsWindowsTarget> + <IsAndroidTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IsAndroidTarget> + <IsIOSTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</IsIOSTarget> + <IsMacCatalystTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</IsMacCatalystTarget> + + <OnnxRuntimeRoot>$(ProjectDir)..\..\..</OnnxRuntimeRoot> + + <!-- Controls whether C# Bindings for Training are included in the Managed Nuget Package. + Bindings for training are included by default. If user tries to call training apis when the native package installed + on their device is not built for training, an exception will be thrown with the following message - + "Training is disabled in the current build. Please build onnxruntime from source with the build flags + enable_training_apis. "--> + <EnableTrainingApis Condition="'$(EnableTrainingApis)' == ''">true</EnableTrainingApis> + </PropertyGroup> + + <!-- package info --> <PropertyGroup> <RootNamespace>Microsoft.ML.OnnxRuntime</RootNamespace> <AssemblyName>Microsoft.ML.OnnxRuntime</AssemblyName> @@ -66,54 +93,31 @@ Commit: $(BUILD_SOURCEVERSION) Build: https://aiinfra.visualstudio.com/Lotus/_build/results?buildId=$(BUILD_BUILDID) </PackageReleaseNotes> + <PackageReadmeFile>README.md</PackageReadmeFile> + <PackageLicenseFile>LICENSE.txt</PackageLicenseFile> + + <!-- sourcelink flags --> + <PublishRepositoryUrl>true</PublishRepositoryUrl> + + <SignAssembly>true</SignAssembly> + <AssemblyOriginatorKeyFile>..\..\OnnxRuntime.snk</AssemblyOriginatorKeyFile> + <AllowedOutputExtensionsInPackageBuildOutputFolder> + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + </AllowedOutputExtensionsInPackageBuildOutputFolder> </PropertyGroup> <PropertyGroup> <Platforms>AnyCPU;x86</Platforms> <LangVersion>default</LangVersion> <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - <SignAssembly>true</SignAssembly> - <AssemblyOriginatorKeyFile>..\..\OnnxRuntime.snk</AssemblyOriginatorKeyFile> - <!--internal build related properties--> - <OnnxRuntimeRoot>$(ProjectDir)..\..\..</OnnxRuntimeRoot> - <OnnxRuntimeCsharpRoot>$(OnnxRuntimeRoot)\csharp</OnnxRuntimeCsharpRoot> <TargetArchitecture Condition=" '$(TargetArchitecture)' == '' ">x64</TargetArchitecture> <EnableDefaultItems>false</EnableDefaultItems> <EnableDefaultCompileItems>false</EnableDefaultCompileItems> <DebugType>portable</DebugType> - <!-- Controls whether C# Bindings for Training are included in the Managed Nuget Package. - Bindings for training are included by default. If user tries to call training apis when the native package installed - on their device is not built for training, an exception will be thrown with the following message - - "Training is disabled in the current build. Please build onnxruntime from source with the build flags - enable_training_apis. "--> - <EnableTrainingApis Condition="'$(EnableTrainingApis)' == ''">true</EnableTrainingApis> - - <!-- sourcelink flags --> - <PublishRepositoryUrl>true</PublishRepositoryUrl> - - <!-- Optional: Embed source files that are not tracked by the source control manager in the PDB --> - <!--EmbedUntrackedSources>true</EmbedUntrackedSources--> - - <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute> - <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> <Configurations>Debug;Release;RelWithDebInfo</Configurations> - - <IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild> - <IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild> - <IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild> - - <!-- $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) gives better results than - $(TargetPlatformIdentifier). See https://github.com/dotnet/msbuild/issues/7359 - Note there are slight differences in casing (e.g. macos vs macOS), so if we ever - change to use $(TargetPlatformIdentifier) we need to adjust for that. - --> - <IsAndroidTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IsAndroidTarget> - <IsIOSTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' OR - $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</IsIOSTarget> - <IsMacTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'macos'">true</IsMacTarget> </PropertyGroup> <!-- Enable training APIs for the build. The native package must be @@ -124,30 +128,19 @@ </PropertyGroup> <!-- - Properties that depend on the system we're building on. + Properties that are used when creating the managed package using the Pack target. --> - <PropertyGroup Condition="'$(IsLinuxBuild)'=='true'"> - <!--internal build related properties for Linux --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Linux</OnnxRuntimeBuildDirectory> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> - </PropertyGroup> - <PropertyGroup Condition="'$(IsWindowsBuild)'=='true'"> - <!--internal build related properties for Windows --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Windows</OnnxRuntimeBuildDirectory> <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir> </PropertyGroup> - - <PropertyGroup Condition="'$(IsMacOSBuild)'=='true'"> - <!--internal build related properties for OSX --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\MacOS</OnnxRuntimeBuildDirectory> + <PropertyGroup Condition="'$(IsLinuxBuild)'=='true'"> <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> </PropertyGroup> <!-- Properties that depend on the target framework. --> - <PropertyGroup Condition="'$(IsIOSTarget)'=='true' OR '$(IsAndroidTarget)'=='true'"> + <PropertyGroup Condition="'$(IsIOSTarget)'=='true' OR '$(IsMacCatalystTarget)'=='true' OR '$(IsAndroidTarget)'=='true'"> <OrtConstants>$(OrtConstants);__MOBILE__</OrtConstants> </PropertyGroup> @@ -155,12 +148,12 @@ <OrtConstants>$(OrtConstants);__ANDROID__</OrtConstants> </PropertyGroup> - <PropertyGroup Condition="'$(IsIOSTarget)'=='true'"> + <PropertyGroup Condition="'$(IsIOSTarget)'=='true' OR '$(IsMacCatalystTarget)'=='true'"> <OrtConstants>$(OrtConstants);__IOS__</OrtConstants> </PropertyGroup> - <!-- CoreML is definitely valid on iOS and macOS --> - <PropertyGroup Condition="'$(IsIOSTarget)'=='true' OR '$(IsMacTarget)'=='true'"> + <!-- CoreML is valid on iOS, Mac Catalyst and macOS --> + <PropertyGroup Condition="'$(IsIOSTarget)'=='true' OR '$(IsMacCatalystTarget)'=='true' OR '$(IsMacOSBuild)'=='true'"> <OrtConstants>$(OrtConstants);__ENABLE_COREML__</OrtConstants> </PropertyGroup> @@ -178,128 +171,6 @@ <DefineConstants>$(DefineConstants);$(OrtConstants)</DefineConstants> </PropertyGroup> - <!-- debug output - makes finding/fixing any issues with the the conditions easy. --> - <Target Name="DumpValues" BeforeTargets="PreBuildEvent"> - <Message Text="SolutionName='$(SolutionName)'" /> - <Message Text="TargetPlatform='$(TargetPlatform)' TargetPlatformIdentifier='$(TargetPlatformIdentifier)' " /> - <Message Text="TargetFramework='$(TargetFramework)' TargetFrameworkIdentifier='$(TargetFrameworkIdentifier)' " /> - <Message Text="[MSBuild]::GetTargetPlatformIdentifier(TargetFramework)='$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))' " /> - <Message Text="[MSBuild]::GetTargetFrameworkIdentifier(TargetFramework)='$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)'))' " /> - <Message Text="IsMacTarget='$(IsMacTarget)' IsIOSTarget='$(IsIOSTarget)' IsAndroidTarget='$(IsAndroidTarget)'" /> - <Message Text="OrtConstants='$(OrtConstants)' " /> - <Message Text="TargetFrameworks='$(TargetFrameworks)' " /> - </Target> - - <ItemGroup> - <None Include="$(OnnxRuntimeCsharpRoot)\..\include\onnxruntime\core\session\onnxruntime_*.h" - PackagePath="\build\native\include" - Pack="false" - CopyToOutputDirectory="Never" - Visible="false" - /> - <None Include="$(OnnxRuntimeCsharpRoot)\..\include\onnxruntime\core\providers\cpu\cpu_provider_factory.h" - PackagePath="\build\native\include" - Pack="false" - CopyToOutputDirectory="Never" - Visible="false" - /> - <None Include="$(OnnxRuntimeCsharpRoot)\..\include\onnxruntime\core\providers\dml\dml_provider_factory.h" - Condition="'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.DirectML'" - PackagePath="\build\native\include" - Pack="false" - CopyToOutputDirectory="Never" - Visible="false" - /> - <None Include="$(OnnxRuntimeCsharpRoot)\..\orttraining\orttraining\training_api\include\onnxruntime_training*.h" - Condition="'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Training'" - PackagePath="\build\native\include" - Pack="false" - CopyToOutputDirectory="Never" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\libonnxruntime.so" - Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')" - PackagePath="\runtimes\linux-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="Never" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\onnxruntime.lib" - Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.lib')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="Never" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\onnxruntime.dll" - Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.dll')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="PreserveNewest" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\onnxruntime.pdb" - Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.pdb')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="PreserveNewest" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\dnnl.dll" - Condition="Exists('$(NativeBuildOutputDir)\dnnl.dll')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="PreserveNewest" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\mklml.dll" - Condition="Exists('$(NativeBuildOutputDir)\mklml.dll')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="PreserveNewest" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\libiomp5md.dll" - Condition="Exists('$(NativeBuildOutputDir)\libiomp5md.dll')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="PreserveNewest" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\tvm.dll" - Condition="Exists('$(NativeBuildOutputDir)\tvm.dll')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - CopyToOutputDirectory="PreserveNewest" - Visible="false" - /> - <None Include="$(OnnxRuntimeCsharpRoot)\..\LICENSE.txt;$(OnnxRuntimeCsharpRoot)\..\ThirdPartyNotices.txt;$(OnnxRuntimeCsharpRoot)\..\ORT_icon_for_light_bg.png;$(OnnxRuntimeCsharpRoot)\..\docs\Privacy.md" - PackagePath="\" - Pack="true" - Visible="false" - /> - <None Include="targets\netstandard\$(PackageId).targets" - PackagePath="build\netstandard2.0\$(PackageId).targets" - Pack="true" - Visible="false" - /> - - <!-- Some tools to be packaged in nightly build only, should not be released --> - <!-- These are copied to the runtimes folder for convenience of loading with the dlls --> - <None Include="$(NativeBuildOutputDir)\onnxruntime_perf_test.exe" - Condition="('$(IsReleaseBuild)' != 'true') And ($(TargetArchitecture)=='x64') And Exists('$(NativeBuildOutputDir)\onnxruntime_perf_test.exe')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - Visible="false" - /> - <None Include="$(NativeBuildOutputDir)\onnx_test_runner.exe" - Condition="('$(IsReleaseBuild)' != 'true') And ($(TargetArchitecture)=='x64') And Exists('$(NativeBuildOutputDir)\onnx_test_runner.exe')" - PackagePath="\runtimes\win-$(TargetArchitecture)\native" - Pack="false" - Visible="false" - /> - </ItemGroup> - <!-- We used to have platform specific files named *.<platform>.cs (e.g. 1.11 release) but don't anymore, so the 'shared' is now meaningless. @@ -313,21 +184,54 @@ <PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" /> </ItemGroup> - <ItemGroup> - <LicenseFile Include="$(OnnxRuntimeCsharpRoot)\..\LICENSE" Visible="false" /> - <TargetsFile Include="$(OnnxRuntimeCsharpRoot)\src\Microsoft.ML.OnnxRuntime\targets\netstandard\targets.xml" Visible="false" /> - </ItemGroup> + <!-- debug output - makes finding/fixing any issues with the the conditions easy. --> + <Target Name="DumpValues" BeforeTargets="PreBuildEvent"> + <Message Text="SolutionName='$(SolutionName)'" /> + <Message Text="TargetPlatform='$(TargetPlatform)' TargetPlatformIdentifier='$(TargetPlatformIdentifier)' " /> + <Message Text="TargetFramework='$(TargetFramework)' TargetFrameworkIdentifier='$(TargetFrameworkIdentifier)' " /> + <Message Text="[MSBuild]::GetTargetPlatformIdentifier(TargetFramework)='$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))' " /> + <Message Text="[MSBuild]::GetTargetFrameworkIdentifier(TargetFramework)='$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)'))' " /> + <Message Text="IsWindowsBuild='$(IsWindowsBuild)' IsLinuxBuild='$(IsLinuxBuild)' IsMacOSBuild='$(IsMacOSBuild)'" /> + <Message Text="IsWindowsTarget='$(IsWindowsTarget)' IsAndroidTarget='$(IsAndroidTarget)' IsIOSTarget='$(IsIOSTarget)' IsMacCatalystTarget='$(IsMacCatalystTarget)'" /> + <Message Text="OrtConstants='$(OrtConstants)' " /> + <Message Text="TargetFrameworks='$(TargetFrameworks)' " /> + </Target> - <Target Name="CopyMiscFiles" BeforeTargets="PreBuildEvent"> - <Copy SourceFiles="@(LicenseFile)" DestinationFiles="@(LicenseFile->'$(OnnxRuntimeCsharpRoot)\..\%(Filename).txt')" /> - <Copy SourceFiles="@(TargetsFile)" DestinationFiles="@(TargetsFile->'$(OnnxRuntimeCsharpRoot)\src\Microsoft.ML.OnnxRuntime\targets\netstandard\$(PackageId).targets')" /> + <!-- + Setup the Pack target related info to create the Microsoft.ML.OnnxRuntime.Managed package + --> + <Target Name="RenameFilesToPack" BeforeTargets="Pack"> + <!-- We (painfully) have to rename files if the extensions differs due to nuget implementation details. --> + <ItemGroup> + <SourceFilesToRename Include=" + $(OnnxRuntimeRoot)\LICENSE; + $(OnnxRuntimeRoot)\csharp\src\Microsoft.ML.OnnxRuntime\targets\netstandard\targets.xml" /> + <DestFilesToRename Include= + "$(NativeBuildOutputDir)\LICENSE.txt; + $(NativeBuildOutputDir)\$(PackageId).targets" /> + </ItemGroup> + <!-- rename the files and output to the native build output dir so we keep the source tree clean --> + <Copy SourceFiles="@(SourceFilesToRename)" DestinationFiles="@(DestFilesToRename)"/> </Target> + <ItemGroup> + <None Include="$(OnnxRuntimeRoot)\ThirdPartyNotices.txt" + PackagePath="ThirdPartyNotices.txt" Pack="true" Visible="false"/> + <None Include="$(OnnxRuntimeRoot)\docs\Privacy.md" + PackagePath="Privacy.md" Pack="true" Visible="false"/> + <None Include="$(OnnxRuntimeRoot)\ORT_icon_for_light_bg.png" + PackagePath="ORT_icon_for_light_bg.png" Pack="true" Visible="false"/> + <None Include="$(OnnxRuntimeRoot)\tools\nuget\nupkg.README.md" + PackagePath="README.md" Pack="true" Visible="false"/> + <None Include="$(NativeBuildOutputDir)\LICENSE.txt" + PackagePath="" Pack="true" Visible="false"/> + <None Include="$(NativeBuildOutputDir)\$(PackageId).targets" + PackagePath="build\netstandard2.0\$(PackageId).targets" Pack="true" Visible="false"/> + </ItemGroup> + <Target Name="CopyPackage" AfterTargets="Pack"> - <Copy - SourceFiles="$(OutputPath)\$(PackageId).$(PackageVersion).nupkg" - DestinationFolder="$(NativeBuildOutputDir)" - /> + <Copy SourceFiles="$(OutputPath)\$(PackageId).$(PackageVersion).nupkg" + DestinationFolder="$(NativeBuildOutputDir)" /> </Target> </Project> diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Microsoft.ML.OnnxRuntime.Tests.Common.csproj b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Microsoft.ML.OnnxRuntime.Tests.Common.csproj index 60d18ad31e811..07ca7fe7c64bf 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Microsoft.ML.OnnxRuntime.Tests.Common.csproj +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Microsoft.ML.OnnxRuntime.Tests.Common.csproj @@ -1,16 +1,19 @@ <Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild> + <IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild> + <IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild> + + <OnnxRuntimeRoot>$(ProjectDir)..\..\..</OnnxRuntimeRoot> + </PropertyGroup> <PropertyGroup> <!-- netstandard2.0 is used by most platforms. net8.0 is required for linux. --> <TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks> <IsPackable>false</IsPackable> - <OnnxRuntimeCsharpRoot>$(ProjectDir)..\..</OnnxRuntimeCsharpRoot> <Platforms>AnyCPU</Platforms> <OutputPath>bin\$(Configuration)\</OutputPath> - <IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild> - <IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild> - <IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild> - <ProtoSrc>$(OnnxRuntimeCsharpRoot)\..\cmake\external\onnx</ProtoSrc> + <ProtoSrc>$(OnnxRuntimeRoot)\cmake\external\onnx</ProtoSrc> <!-- Generated OnnxML.cs triggers this warning. --> <NoWarn>8981</NoWarn> @@ -22,30 +25,22 @@ <AssemblyOriginatorKeyFile>..\..\OnnxRuntime.snk</AssemblyOriginatorKeyFile> <Configurations>Debug;Release;RelWithDebInfo</Configurations> <!-- end --> + <RootNamespace>Microsoft.ML.OnnxRuntime.Tests</RootNamespace> <AssemblyName>Microsoft.ML.OnnxRuntime.Tests.Common</AssemblyName> </PropertyGroup> - <PropertyGroup Condition="'$(IsLinuxBuild)'=='true'"> - <!--internal build related properties for Linux --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Linux</OnnxRuntimeBuildDirectory> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> - <ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake</ProtocDirectory> - <ProtocExe>$(ProtocDirectory)\protoc</ProtocExe> - </PropertyGroup> - <PropertyGroup Condition="'$(IsWindowsBuild)'=='true'"> - <!--internal build related properties for Windows --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Windows</OnnxRuntimeBuildDirectory> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir> <ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake\$(Configuration)</ProtocDirectory> <ProtocExe>$(ProtocDirectory)\protoc.exe</ProtocExe> </PropertyGroup> + <PropertyGroup Condition="'$(IsLinuxBuild)'=='true'"> + <ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake</ProtocDirectory> + <ProtocExe>$(ProtocDirectory)\protoc</ProtocExe> + </PropertyGroup> + <PropertyGroup Condition="'$(IsMacOSBuild)'=='true'"> - <!--internal build related properties for OSX --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\MacOS</OnnxRuntimeBuildDirectory> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> <ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake</ProtocDirectory> <ProtocExe>$(ProtocDirectory)\protoc</ProtocExe> </PropertyGroup> @@ -102,28 +97,6 @@ </None> </ItemGroup> - <!-- - Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj handles the native lib coming from a local build or a nuget package so we - don't need to duplicate that logic to include the native lib here. - --> - <ItemGroup Condition="$(SkipNativeLibInclude) != 'true'"> - <None Condition="'$(IsWindowsBuild)'=='true'" - Include="$(NativeBuildOutputDir)\onnxruntime.dll;$(NativeBuildOutputDir)\onnxruntime.pdb"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - - <None Condition="'$(IsLinuxBuild)'=='true'" Include="$(NativeBuildOutputDir)\libonnxruntime.so"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - - <None Condition="'$(IsMacOSBuild)'=='true'" Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - </ItemGroup> - <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" /> <PackageReference Include="Google.Protobuf" Version="3.21.12" /> @@ -132,16 +105,20 @@ </ItemGroup> <ItemGroup> - <ProjectReference Include="$(OnnxRuntimeCsharpRoot)\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" /> + <ProjectReference Include="$(OnnxRuntimeRoot)\csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" /> </ItemGroup> <!-- generate OnnxMl.cs from ONNX protobuf definition --> <Target Name="ProtoGen" BeforeTargets="BeforeBuild" Condition="Exists('$(ProtocExe)')"> - <Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-ml.proto3" ContinueOnError="false"></Exec> + <Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-ml.proto3" + ContinueOnError="false"> + </Exec> </Target> <Target Name="ProtoDataGen" BeforeTargets="BeforeBuild" Condition="Exists('$(ProtocExe)')"> - <Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-data.proto3" ContinueOnError="false"></Exec> + <Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-data.proto3" + ContinueOnError="false"> + </Exec> </Target> <ItemGroup> @@ -152,20 +129,20 @@ <WriteLinesToFile File="$(OutputPath)\Properties.txt" Lines="@(BuildEnvVars)" Overwrite="true" /> </Target> + <!-- Test Data that is used in MAUI and NetCore test app. Loaded via embedded resource for that to be possible --> <ItemGroup> <EmbeddedResource Include="..\..\testdata\*"> - <Link>TestData\%(Filename)%(Extension)</Link> + <Link>TestData\%(Filename)%(Extension)</Link> </EmbeddedResource> - <EmbeddedResource Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\overridable_initializer.onnx"> - <Link>TestData\overridable_initializer.onnx</Link> + <EmbeddedResource Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\overridable_initializer.onnx"> + <Link>TestData\overridable_initializer.onnx</Link> </EmbeddedResource> - <EmbeddedResource Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\capi_symbolic_dims.onnx"> - <Link>TestData\capi_symbolic_dims.onnx</Link> + <EmbeddedResource Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\capi_symbolic_dims.onnx"> + <Link>TestData\capi_symbolic_dims.onnx</Link> </EmbeddedResource> </ItemGroup> <ItemGroup> <Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" /> </ItemGroup> - </Project> diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/NativeLibraryInclude.props b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/NativeLibraryInclude.props new file mode 100644 index 0000000000000..3daab21dbcbac --- /dev/null +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/NativeLibraryInclude.props @@ -0,0 +1,171 @@ +<!-- +Add the native libraries from either a local build or a prebuilt native nuget package. + +This has to be imported by the test project with the actual target platform/frameworks to work correctly as the common +test project only targets net8 and netstandard2.0. +--> +<Project> + <PropertyGroup> + <!-- build host system --> + <IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild> + <IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild> + <IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild> + + <!-- set for MAUI targets --> + <IsWindowsTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">true</IsWindowsTarget> + <IsAndroidTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IsAndroidTarget> + <IsIOSTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</IsIOSTarget> + <IsMacCatalystTarget Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</IsMacCatalystTarget> + + <!-- + Allow a pre-built ORT native nuget package (Microsoft.ML.OnnxRuntime.<version>.nupkg) to be used. + + The test projects that include this file must be built from the command-line to enable using a prebuilt package. + Current test projects: + - Microsoft.ML.OnnxRuntime.Tests.NetCoreApp + - Microsoft.ML.OnnxRuntime.Tests.MAUI + + If running from the repo root the below is an example command. + Note that '==' represents a double '-' which isn't allowed in an XML comment + Properties can also be set via environment variables. + + dotnet build csharp\test\Microsoft.ML.OnnxRuntime.Tests.MAUI\Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj + ==property:UsePrebuiltNativePackage=true + ==property:CurrentOnnxRuntimeVersion=1.19.2 + ==source <path containing the Microsoft.ML.OnnxRuntime.<version>.nupkg> + ==source https://api.nuget.org/v3/index.json + + The <version> of the nupkg must match the value provided in CurrentOnnxRuntimeVersion. + + The "==source" args are not required if a released Microsoft.ML.OnnxRuntime package is being used. + If using a previous release you must ensure it is compatible with the entries in NativeMethods.shared.cs. + If new bindings have been added recently you will get error when those are initialized if the native code is out + of date and does not match. + --> + <UsePrebuiltNativePackage Condition="'$(UsePrebuiltNativePackage)' == ''">false</UsePrebuiltNativePackage> + <CurrentOnnxRuntimeVersion Condition="'$(CurrentOnnxRuntimeVersion)' == ''">1.20.0-dev-20241007</CurrentOnnxRuntimeVersion> + </PropertyGroup> + + <!-- debug output - makes finding/fixing any issues with the the conditions easy. --> + <Target Name="DumpValues" BeforeTargets="PreBuildEvent"> + <Message Text="NativeLibraryInclude: TargetPlatform='$(TargetPlatform)' TargetPlatformIdentifier='$(TargetPlatformIdentifier)' " /> + <Message Text="TargetFramework='$(TargetFramework)' TargetFrameworkIdentifier='$(TargetFrameworkIdentifier)' " /> + <Message Text="[MSBuild]::GetTargetPlatformIdentifier(TargetFramework)='$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))' " /> + <Message Text="[MSBuild]::GetTargetFrameworkIdentifier(TargetFramework)='$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)'))' " /> + <Message Text="IsWindowsBuild='$(IsWindowsBuild)' IsLinuxBuild='$(IsLinuxBuild)' IsMacOSBuild='$(IsMacOSBuild)'" /> + <Message Text="IsWindowsTarget='$(IsWindowsTarget)' IsAndroidTarget='$(IsAndroidTarget)' IsIOSTarget='$(IsIOSTarget)' IsMacCatalystTarget='$(IsMacCatalystTarget)'" /> + </Target> + + <ItemGroup Condition="'$(UsePrebuiltNativePackage)' == 'true'"> + <!-- Use the prebuilt package --> + <PackageReference Include="Microsoft.ML.OnnxRuntime" Version="$(CurrentOnnxRuntimeVersion)" /> + </ItemGroup> + + <!-- 'Choose' so we don't need the UsePrebuiltNativePackage condition on all the PropertyGroup/ItemGroup elements --> + <Choose> + <When Condition="'$(UsePrebuiltNativePackage)' != 'true'"> + <PropertyGroup Condition="'$(IsWindowsBuild)'=='true' OR '$(IsWindowsTarget)'=='true'"> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Windows</OnnxRuntimeBuildDirectory> + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir> + </PropertyGroup> + + <PropertyGroup Condition="'$(IsLinuxBuild)'=='true'"> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Linux</OnnxRuntimeBuildDirectory> + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> + </PropertyGroup> + + <PropertyGroup Condition="'$(IsMacOSBuild)'=='true'"> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\MacOS</OnnxRuntimeBuildDirectory> + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> + </PropertyGroup> + + <PropertyGroup Condition="'$(IsAndroidTarget)' == 'true'"> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Android</OnnxRuntimeBuildDirectory> + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> + </PropertyGroup> + + <PropertyGroup Condition="'$(IsIOSTarget)' == 'true'"> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\iOS</OnnxRuntimeBuildDirectory> + <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform> + <PlatformLower>$(Platform.ToLower())</PlatformLower> + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)-$(PlatformLower)</NativeBuildOutputDir> + </PropertyGroup> + + <PropertyGroup Condition="'$(IsMacCatalystTarget)' == 'true'"> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\macOS</OnnxRuntimeBuildDirectory> + <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> + </PropertyGroup> + + <ItemGroup Condition="'$(IsWindowsBuild)' == 'true' OR '$(IsWindowsTarget)'=='true'"> + <None Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.dll')" + Include="$(NativeBuildOutputDir)\*.dll;$(NativeBuildOutputDir)\*.pdb"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + <Visible>true</Visible> + </None> + </ItemGroup> + + <ItemGroup Condition="'$(IsLinuxBuild)' == 'true'"> + <None Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')" + Include="$(NativeBuildOutputDir)\libonnxruntime.so"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + <Visible>false</Visible> + </None> + </ItemGroup> + + <ItemGroup Condition="'$(IsMacOSBuild)' == 'true'"> + <None Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" + Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + <Visible>false</Visible> + </None> + </ItemGroup> + + <ItemGroup Condition="'$(IsAndroidTarget)' == 'true'"> + <AndroidNativeLibrary Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')" + Include="$(NativeBuildOutputDir)\libonnxruntime.so"> + <Link>libs\libonnxruntime.so</Link> + </AndroidNativeLibrary> + </ItemGroup> + + <ItemGroup Condition="'$(IsIOSTarget)' == 'true'"> + <NativeReference Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" + Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> + <Link>libs\libonnxruntime.dylib</Link> + <Kind>Dynamic</Kind> + <ForceLoad>True</ForceLoad> + <IsCxx>True</IsCxx> + </NativeReference> + </ItemGroup> + + <ItemGroup Condition="'$(IsMacCatalystTarget)' == 'true'"> + <NativeReference Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" + Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> + <Link>libs\libonnxruntime.dylib</Link> + <Kind>Dynamic</Kind> + <ForceLoad>True</ForceLoad> + <IsCxx>True</IsCxx> + </NativeReference> + </ItemGroup> + </When> + </Choose> + + <!-- Property debug output. --> + <PropertyGroup> + <!-- local builds--> + <HaveOrtDll>false</HaveOrtDll> + <HaveOrtDll Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.dll')">true</HaveOrtDll> + <HaveOrtSo>false</HaveOrtSo> + <HaveOrtSo Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')">true</HaveOrtSo> + <HaveOrtDylib>false</HaveOrtDylib> + <HaveOrtDylib Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')">true</HaveOrtDylib> + </PropertyGroup> + + <Target Name="DumpLocalBuild" BeforeTargets="PreBuildEvent"> + <Message Text="Prebuilt runtime=$(UsePrebuiltNativePackage)" /> + <Message Text="NativeBuildOutputDir=$(NativeBuildOutputDir)" /> + <Message Text="onnxruntime.dll from local build=$(HaveOrtDll)" /> + <Message Text="libonnxruntime.so from local build=$(HaveOrtSo)" /> + <Message Text="libonnxruntime.dylib from local build=$(HaveOrtDylib)" /> + </Target> + +</Project> diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Tensors/TensorTests.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Tensors/TensorTests.cs index 27cde1dbe9ed8..46dd292e8514e 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Tensors/TensorTests.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Tensors/TensorTests.cs @@ -2180,10 +2180,13 @@ public void GetArrayString(TensorConstructor constructor) {22,23} } }"; + // remove \r so the newlines are just \n on all platforms + expected = expected.Replace("\r", ""); + var actual= tensor.GetArrayString().Replace("\r", ""); - Assert.Equal(expected, tensor.GetArrayString()); + Assert.Equal(expected, actual); - var expectedNoSpace = expected.Replace(Environment.NewLine, "").Replace(" ", ""); + var expectedNoSpace = expected.Replace("\n", "").Replace(" ", ""); Assert.Equal(expectedNoSpace, tensor.GetArrayString(false)); } diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.MAUI/Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.MAUI/Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj index 210a04d78f107..e07448daeea7f 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.MAUI/Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.MAUI/Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj @@ -1,306 +1,125 @@ <Project Sdk="Microsoft.NET.Sdk"> - <!-- ORT specific high level properties --> - <PropertyGroup> - <IsWindowsBuild Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">true</IsWindowsBuild> - <IsAndroidBuild Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">true</IsAndroidBuild> - <IsIOSBuild Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">true</IsIOSBuild> - <IsMacCatalystBuild Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</IsMacCatalystBuild> - <OnnxRuntimeRoot>$(ProjectDir)..\..\..</OnnxRuntimeRoot> - </PropertyGroup> - - <!-- General app properties --> - <PropertyGroup> - <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> - <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> - - <!-- Note for MacCatalyst: - The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64. - When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>. - The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated; - either BOTH runtimes must be indicated or ONLY macatalyst-x64. --> - <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> --> - - <OutputType>Exe</OutputType> - <RootNamespace>Microsoft.ML.OnnxRuntime.Tests.MAUI</RootNamespace> - <UseMaui>true</UseMaui> - <SingleProject>true</SingleProject> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - <AllowUnsafeBlocks>true</AllowUnsafeBlocks> - <!-- some of the helper packages don't have strong named assemblies. --> - <NoWarn>8002</NoWarn> - - <!-- These are copied from the sample. TBD what we really need. --> - <DefineConstants Condition="'$(CI)' != 'true'">$(DefineConstants);INCLUDE_FAILING_TESTS</DefineConstants> - <DefineConstants Condition="'$(TestingMode)' == 'NonInteractiveVisual'">$(DefineConstants);MODE_NON_INTERACTIVE_VISUAL</DefineConstants> - <DefineConstants Condition="'$(TestingMode)' == 'XHarness'">$(DefineConstants);MODE_XHARNESS</DefineConstants> - - <!-- Display name --> - <ApplicationTitle>Microsoft.ML.OnnxRuntime.Tests.MAUI</ApplicationTitle> - - <!-- App Identifier. MUST be short or you get a misleading error about not being able to deploy the app --> - <ApplicationId>ORT.CSharp.Tests.MAUI</ApplicationId> - - <!-- Versions --> - <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> - <ApplicationVersion>1</ApplicationVersion> - - <SupportedOSPlatformVersion Condition="'$(IsIOSBuild)' == 'true'">15.0</SupportedOSPlatformVersion> - <SupportedOSPlatformVersion Condition="'$(IsMacCatalystBuild)' == 'true'">13.1</SupportedOSPlatformVersion> - <SupportedOSPlatformVersion Condition="'$(IsAndroidBuild)' == 'true'">30.0</SupportedOSPlatformVersion> - <SupportedOSPlatformVersion Condition="'$(IsWindowsBuild)' == 'true'">10.0.17763.0</SupportedOSPlatformVersion> - <TargetPlatformMinVersion Condition="'$(IsWindowsBuild)' == 'true'">10.0.17763.0</TargetPlatformMinVersion> - - <SignAssembly>true</SignAssembly> - <AssemblyOriginatorKeyFile>..\..\OnnxRuntime.snk</AssemblyOriginatorKeyFile> - - <!-- Multiple csproj files copy the ORT dll and pdb files. --> - <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles> - </PropertyGroup> - - <!-- - Setup directories to find ORT native binary. - - You can use a released Microsoft.ML.OnnxRuntime nuget package or a recent build from - https://aiinfra.visualstudio.com/PublicPackages/_artifacts/feed/ORT-Nightly if testing C# changes. - The native nuget package contains Windows, Android, macOS, mac-catalyst and iOS builds. - - Unzip the nupkg file in the /build directory to create /build/microsoft.ml.onnxruntime.1.18.1 directory. - Adjust the version number as needed. - - If testing changes to the native library, build locally with the `<dash><dash>build_csharp` flag so that - OnnxRuntimeBuildDirectory is set to the build output directory. Adjust the build path if necessary. - --> - <PropertyGroup> - <PrebuiltRuntimesDir>$(OnnxRuntimeRoot)\build\microsoft.ml.onnxruntime.1.18.1\runtimes</PrebuiltRuntimesDir> - <!-- - set this so Microsoft.ML.OnnxRuntime.Tests.Common.csproj lets us do the include of the native library - as it may come from a local build or a nuget package. This saves duplicating the include logic. - --> - <SkipNativeLibInclude>true</SkipNativeLibInclude> - </PropertyGroup> - - <PropertyGroup Condition="'$(IsWindowsBuild)' == 'true'"> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Windows</OnnxRuntimeBuildDirectory> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir> - <!-- TODO: support other architectures if needed. --> - <PrebuiltWinDir>$(PrebuiltRuntimesDir)\win-x64\native</PrebuiltWinDir> - </PropertyGroup> - <PropertyGroup Condition="'$(IsAndroidBuild)' == 'true'"> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Android</OnnxRuntimeBuildDirectory> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> - <PrebuiltAAR>$(PrebuiltRuntimesDir)\android\native\onnxruntime.aar</PrebuiltAAR> - </PropertyGroup> - <PropertyGroup Condition="'$(IsIOSBuild)' == 'true'"> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\iOS</OnnxRuntimeBuildDirectory> - <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform> - <PlatformLower>$(Platform.ToLower())</PlatformLower> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)-$(PlatformLower)</NativeBuildOutputDir> - <PrebuiltFramework>$(PrebuiltRuntimesDir)\ios\native\onnxruntime.xcframework</PrebuiltFramework> - </PropertyGroup> - <PropertyGroup Condition="'$(IsMacCatalystBuild)' == 'true'"> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\macOS</OnnxRuntimeBuildDirectory> - <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> - <PrebuiltFramework>$(PrebuiltRuntimesDir)\ios\native\onnxruntime.xcframework</PrebuiltFramework> - </PropertyGroup> - - <ItemGroup Condition="'$(IsWindowsBuild)' == 'true'"> - <!-- local build --> - <None Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.dll')" - Include="$(NativeBuildOutputDir)\*.dll;$(NativeBuildOutputDir)\*.pdb"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>true</Visible> - </None> - - <!-- build from package --> - <None Condition="!Exists('$(NativeBuildOutputDir)\onnxruntime.dll')" - Include="$(PrebuiltWinDir)\*.*"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>true</Visible> - </None> - - <!-- test data --> - <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\*"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\overridable_initializer.onnx"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\capi_symbolic_dims.onnx"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\custom_op_library\custom_op_test.onnx"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\lora\two_params_lora_model.onnx"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\lora\two_params_lora_model.onnx_adapter"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - </ItemGroup> - - <ItemGroup Condition="'$(IsAndroidBuild)' == 'true'"> - <!-- local build --> - <AndroidNativeLibrary Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')" - Include="$(NativeBuildOutputDir)\libonnxruntime.so"> - <Link>libs\libonnxruntime.so</Link> - </AndroidNativeLibrary> - - <!-- build from package --> - <AndroidLibrary - Bind="false" - Condition="Exists('$(PrebuiltAAR)') AND !Exists('$(NativeBuildOutputDir)\libonnxruntime.so')" - Include="$(PrebuiltAAR)"/> - </ItemGroup> - - <ItemGroup Condition="'$(IsIOSBuild)' == 'true'"> - <!-- local build of shared lib --> - <NativeReference - Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" - Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> - <Link>libs\libonnxruntime.dylib</Link> - <Kind>Dynamic</Kind> - <ForceLoad>True</ForceLoad> - <IsCxx>True</IsCxx> - </NativeReference> - - <!-- build from package --> - <NativeReference - Condition="Exists('$(PrebuiltFramework)') AND !Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" - Include="$(PrebuiltFramework)"> - <Kind>Framework</Kind> - <ForceLoad>True</ForceLoad> - <IsCxx>True</IsCxx> - </NativeReference> - </ItemGroup> - - <ItemGroup Condition="'$(IsMacCatalystBuild)' == 'true'"> - <!-- local build --> - <NativeReference Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" - Include="$(NativeBuildOutputDir)\libonnxruntime.dylib"> - <Link>libs\libonnxruntime.dylib</Link> - <Kind>Dynamic</Kind> - <ForceLoad>True</ForceLoad> - <IsCxx>True</IsCxx> - </NativeReference> - - <!-- build from package --> - <NativeReference - Condition="Exists('$(PrebuiltFramework)') AND !Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')" - Include="$(PrebuiltFramework)"> - <Kind>Framework</Kind> - <ForceLoad>True</ForceLoad> - <IsCxx>True</IsCxx> - </NativeReference> - </ItemGroup> - - <!-- Property debug output - makes finding/fixing any issues with the conditions easy. --> - <PropertyGroup> - <!-- local builds--> - <HaveOrtDll>false</HaveOrtDll> - <HaveOrtDll Condition="Exists('$(NativeBuildOutputDir)\onnxruntime.dll')">true</HaveOrtDll> - <HaveOrtSo>false</HaveOrtSo> - <HaveOrtSo Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.so')">true</HaveOrtSo> - <HaveOrtDylib>false</HaveOrtDylib> - <HaveOrtDylib Condition="Exists('$(NativeBuildOutputDir)\libonnxruntime.dylib')">true</HaveOrtDylib> - <!-- prebuilt --> - <HavePrebuilt>false</HavePrebuilt> - <HavePrebuilt Condition="Exists('$(PrebuiltWinDir)')">true</HavePrebuilt> - <HaveAAR>false</HaveAAR> - <HaveAAR Condition="Exists('$(PrebuiltAAR)')">true</HaveAAR> - <HaveFramework>false</HaveFramework> - <HaveFramework Condition="Exists('$(PrebuiltFramework)')">true</HaveFramework> - </PropertyGroup> - - <Target Name="DumpValues" BeforeTargets="PreBuildEvent"> - <Message Text="TargetFramework=$(TargetFramework)" /> - <Message Text="Platform=$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))" /> - <Message Text="OnnxRuntimeRoot=$(OnnxRuntimeRoot)" /> - <Message Text="NativeBuildOutputDir=$(NativeBuildOutputDir)" /> - <Message Text="IsWindowsBuild='$(IsWindowsBuild)'" /> - <Message Text="IsAndroidBuild='$(IsAndroidBuild)'" /> - <Message Text="IsIOSBuild='$(IsIOSBuild)'" /> - <Message Text="IsMacCatalystBuild='$(IsMacCatalystBuild)'" /> - <Message Text="onnxruntime.dll from local build=$(HaveOrtDll)" /> - <Message Text="libonnxruntime.so from local build=$(HaveOrtSo)" /> - <Message Text="libonnxruntime.dylib from local build=$(HaveOrtDylib)" /> - <Message Text="Prebuilt runtime=$(HavePrebuilt)" /> - <Message Text="Prebuilt AAR=$(HaveAAR)" /> - <Message Text="Prebuilt xcframework=$(HaveFramework)" /> - </Target> - - <ItemGroup> - <!-- App Icon --> - <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> - - <!-- Splash Screen --> - <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> - - <!-- Images --> - <MauiImage Include="Resources\Images\*" /> - <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" /> - - <!-- Custom Fonts --> - <MauiFont Include="Resources\Fonts\*" /> - - <!-- Raw Assets (also remove the "Resources\Raw" prefix) --> - <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> - </ItemGroup> - - <ItemGroup> - <Compile Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\InferenceTest.cs"> - <Link>InferenceTest.cs</Link> - </Compile> - <Compile Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\OrtIoBindingAllocationTest.cs"> - <Link>OrtIoBindingAllocationTest.cs</Link> - </Compile> - <Compile Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\Tensors\TensorTests.cs"> - <Link>TensorTests.cs</Link> - </Compile> - </ItemGroup> - - <ItemGroup> - <ProjectReference - Include="..\..\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" - name="Microsoft.ML.OnnxRuntime" /> - <ProjectReference - Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\Microsoft.ML.OnnxRuntime.Tests.Common.csproj" - name="Microsoft.ML.OnnxRuntime.Tests.Common" /> - <ProjectReference - Include="..\Microsoft.ML.OnnxRuntime.Tests.Devices\Microsoft.ML.OnnxRuntime.Tests.Devices.csproj" - name="Microsoft.ML.OnnxRuntime.Tests.Devices" /> - </ItemGroup> - - <ItemGroup> - <PackageReference Include="DeviceRunners.VisualRunners.Maui" Version="0.1.0-preview.2" /> - <PackageReference Include="DeviceRunners.VisualRunners.Xunit" Version="0.1.0-preview.2" /> - <PackageReference Include="DeviceRunners.XHarness.Maui" Version="0.1.0-preview.2" /> - <PackageReference Include="DeviceRunners.XHarness.Xunit" Version="0.1.0-preview.2" /> - <PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="9.0.0-prerelease.24374.1" /> - <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.70" /> - <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.70" /> - <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> - <PackageReference Include="xunit" Version="2.9.0" /> - <PackageReference Include="xunit.runner.utility" Version="2.9.0" /> - </ItemGroup> - - <ItemGroup Condition="$(IsIOSBuild)=='true' OR $(IsMacCatalystBuild)=='true'"> - <!-- need the dummy ORT Extensions package to resolve the RegisterCustomOps symbol. - TODO: Update to 0.12.0 when released so there's a mac-catalyst build in the package. --> - <PackageReference Include="Microsoft.ML.OnnxRuntime.Extensions.Dummy" Version="0.10.0" /> - </ItemGroup> - - <Target Name="RemoveVisualStudioTestRunner" BeforeTargets="_ComputeAppxPackagePayload"> - <ItemGroup> - <_VisualStudioTestRunnerFiles Include="@(PackagingOutputs)" Condition="$([System.String]::Copy('%(PackagingOutputs.FullPath)').Contains('xunit.runner.visualstudio'))" /> - <PackagingOutputs Remove="@(_VisualStudioTestRunnerFiles)" /> - </ItemGroup> - </Target> + <PropertyGroup> + <OnnxRuntimeRoot>$(ProjectDir)..\..\..</OnnxRuntimeRoot> + </PropertyGroup> + + <Import Project="../Microsoft.ML.OnnxRuntime.Tests.Common/NativeLibraryInclude.props" /> + + <!-- General app properties --> + <PropertyGroup> + <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> + <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> + + <!-- Note for MacCatalyst: + The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64. + When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>. + The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated; + either BOTH runtimes must be indicated or ONLY macatalyst-x64. --> + <!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> --> + + <OutputType>Exe</OutputType> + <RootNamespace>Microsoft.ML.OnnxRuntime.Tests.MAUI</RootNamespace> + <UseMaui>true</UseMaui> + <SingleProject>true</SingleProject> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <!-- some of the helper packages don't have strong named assemblies. --> + <NoWarn>8002</NoWarn> + + <!-- These are copied from the sample. TBD what we really need. --> + <DefineConstants Condition="'$(CI)' != 'true'">$(DefineConstants);INCLUDE_FAILING_TESTS</DefineConstants> + <DefineConstants Condition="'$(TestingMode)' == 'NonInteractiveVisual'">$(DefineConstants);MODE_NON_INTERACTIVE_VISUAL</DefineConstants> + <DefineConstants Condition="'$(TestingMode)' == 'XHarness'">$(DefineConstants);MODE_XHARNESS</DefineConstants> + + <!-- Display name --> + <ApplicationTitle>Microsoft.ML.OnnxRuntime.Tests.MAUI</ApplicationTitle> + + <!-- App Identifier. MUST be short or you get a misleading error about not being able to deploy the app --> + <ApplicationId>ORT.CSharp.Tests.MAUI</ApplicationId> + + <!-- Versions --> + <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> + <ApplicationVersion>1</ApplicationVersion> + + <SupportedOSPlatformVersion Condition="'$(IsIOSTarget)' == 'true'">15.0</SupportedOSPlatformVersion> + <SupportedOSPlatformVersion Condition="'$(IsMacCatalystTarget)' == 'true'">13.1</SupportedOSPlatformVersion> + <SupportedOSPlatformVersion Condition="'$(IsAndroidTarget)' == 'true'">30.0</SupportedOSPlatformVersion> + <SupportedOSPlatformVersion Condition="'$(IsWindowsTarget)' == 'true'">10.0.17763.0</SupportedOSPlatformVersion> + <TargetPlatformMinVersion Condition="'$(IsWindowsTarget)' == 'true'">10.0.17763.0</TargetPlatformMinVersion> + + <SignAssembly>true</SignAssembly> + <AssemblyOriginatorKeyFile>..\..\OnnxRuntime.snk</AssemblyOriginatorKeyFile> + </PropertyGroup> + + <ItemGroup> + <!-- App Icon --> + <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" /> + + <!-- Splash Screen --> + <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> + + <!-- Images --> + <MauiImage Include="Resources\Images\*" /> + <MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" /> + + <!-- Custom Fonts --> + <MauiFont Include="Resources\Fonts\*" /> + + <!-- Raw Assets (also remove the "Resources\Raw" prefix) --> + <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> + </ItemGroup> + + <!-- NOTE: The xUnit framework doesn't pickup the tests defined within the referenced + Microsoft.ML.OnnxRuntime.Tests.Common project --> + <ItemGroup> + <Compile Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\InferenceTest.cs"> + <Link>InferenceTest.cs</Link> + </Compile> + <Compile Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\OrtIoBindingAllocationTest.cs"> + <Link>OrtIoBindingAllocationTest.cs</Link> + </Compile> + <Compile Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\Tensors\TensorTests.cs"> + <Link>TensorTests.cs</Link> + </Compile> + </ItemGroup> + + <ItemGroup> + <ProjectReference + Include="..\..\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" + name="Microsoft.ML.OnnxRuntime" /> + <ProjectReference + Include="..\Microsoft.ML.OnnxRuntime.Tests.Common\Microsoft.ML.OnnxRuntime.Tests.Common.csproj" + name="Microsoft.ML.OnnxRuntime.Tests.Common" /> + <ProjectReference + Include="..\Microsoft.ML.OnnxRuntime.Tests.Devices\Microsoft.ML.OnnxRuntime.Tests.Devices.csproj" + name="Microsoft.ML.OnnxRuntime.Tests.Devices" /> + </ItemGroup> + + <ItemGroup> + <PackageReference Include="DeviceRunners.VisualRunners.Maui" Version="0.1.0-preview.2" /> + <PackageReference Include="DeviceRunners.VisualRunners.Xunit" Version="0.1.0-preview.2" /> + <PackageReference Include="DeviceRunners.XHarness.Maui" Version="0.1.0-preview.2" /> + <PackageReference Include="DeviceRunners.XHarness.Xunit" Version="0.1.0-preview.2" /> + <PackageReference Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="9.0.0-prerelease.24374.1" /> + <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.70" /> + <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.70" /> + <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" /> + <PackageReference Include="xunit" Version="2.9.0" /> + <PackageReference Include="xunit.runner.utility" Version="2.9.0" /> + </ItemGroup> + + <ItemGroup Condition="$(IsIOSTarget)=='true' OR $(IsMacCatalystTarget)=='true'"> + <!-- need the dummy ORT Extensions package to resolve the RegisterCustomOps symbol. --> + <PackageReference Include="Microsoft.ML.OnnxRuntime.Extensions.Dummy" Version="0.12.0" /> + </ItemGroup> + + <Target Name="RemoveVisualStudioTestRunner" BeforeTargets="_ComputeAppxPackagePayload"> + <ItemGroup> + <_VisualStudioTestRunnerFiles + Include="@(PackagingOutputs)" + Condition="$([System.String]::Copy('%(PackagingOutputs.FullPath)').Contains('xunit.runner.visualstudio'))" /> + <PackagingOutputs Remove="@(_VisualStudioTestRunnerFiles)" /> + </ItemGroup> + </Target> </Project> diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.MAUI/ReadMe.md b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.MAUI/ReadMe.md new file mode 100644 index 0000000000000..07cb5fe7c9b3d --- /dev/null +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.MAUI/ReadMe.md @@ -0,0 +1,9 @@ +The MAUI test project can be optionally used with a pre-built ONNX Runtime native nuget package (Microsoft.ML.OnnxRuntime). + +To do so, specify the `UsePrebuiltNativePackage` and `CurrentOnnxRuntimeVersion` properties when building the project. These can be set via the command-line or as environment variables. + +For example: + +```cmd +dotnet build csharp\test\Microsoft.ML.OnnxRuntime.Tests.MAUI\Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj --property:UsePrebuiltNativePackage=true --property:CurrentOnnxRuntimeVersion=1.19.2 --source directory_containing_native_nuget_package --source https://api.nuget.org/v3/index.json +``` diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp.csproj b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp.csproj index b822c999e4d39..a8abcd2b4aa1c 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp.csproj +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp/Microsoft.ML.OnnxRuntime.Tests.NetCoreApp.csproj @@ -1,4 +1,9 @@ <Project Sdk="Microsoft.NET.Sdk"> + <PropertyGroup> + <OnnxRuntimeRoot>$(ProjectDir)..\..\..</OnnxRuntimeRoot> + </PropertyGroup> + + <Import Project="../Microsoft.ML.OnnxRuntime.Tests.Common/NativeLibraryInclude.props" /> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> @@ -6,9 +11,7 @@ <OnnxRuntimeCsharpRoot>$(ProjectDir)..\..</OnnxRuntimeCsharpRoot> <Platforms>AnyCPU;x86</Platforms> <OutputPath>bin\$(Configuration)\</OutputPath> - <IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild> - <IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild> - <IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild> + <ProtoSrc>$(OnnxSourceDirectory)\onnx</ProtoSrc> <!-- following attributes were necessary for the migrated Tensor tests --> <LangVersion>default</LangVersion> @@ -35,19 +38,19 @@ <PropertyGroup Condition="'$(IsLinuxBuild)'=='true'"> <!--internal build related properties for Linux --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Linux</OnnxRuntimeBuildDirectory> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Linux</OnnxRuntimeBuildDirectory> <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> </PropertyGroup> <PropertyGroup Condition="'$(IsWindowsBuild)'=='true'"> <!--internal build related properties for Windows --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Windows</OnnxRuntimeBuildDirectory> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\Windows</OnnxRuntimeBuildDirectory> <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir> </PropertyGroup> <PropertyGroup Condition="'$(IsMacOSBuild)'=='true'"> <!--internal build related properties for OSX --> - <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\MacOS</OnnxRuntimeBuildDirectory> + <OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeRoot)\build\MacOS</OnnxRuntimeBuildDirectory> <NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir> </PropertyGroup> @@ -58,15 +61,14 @@ </ItemGroup> <!-- - Copy the required libraries for testing to the output directory. + Additional libraries that aren't copied by Microsoft.ML.OnnxRuntime.Tests.Common.csproj + NOTE: We use a wildcard for custom_op_library even though that isn't necessary, so it doesn't fail if the custom op library isn't present, which it may not be depending on the ORT build settings. --> <ItemGroup> <None Condition="'$(IsWindowsBuild)'=='true'" - Include="$(NativeBuildOutputDir)\onnxruntime.dll; - $(NativeBuildOutputDir)\onnxruntime.pdb; - $(NativeBuildOutputDir)\onnxruntime_providers_*.dll; + Include="$(NativeBuildOutputDir)\onnxruntime_providers_*.dll; $(NativeBuildOutputDir)\onnxruntime_providers_*.pdb; $(NativeBuildOutputDir)\custom_op_library*.dll"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> @@ -74,45 +76,39 @@ </None> <None Condition="'$(IsLinuxBuild)'=='true'" - Include="$(NativeBuildOutputDir)\libonnxruntime.so; - $(NativeBuildOutputDir)\libonnxruntime_providers_*.so; + Include="$(NativeBuildOutputDir)\libonnxruntime_providers_*.so; $(NativeBuildOutputDir)\libcustom_op_library*.so"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>false</Visible> </None> <None Condition="'$(IsMacOSBuild)'=='true'" - Include="$(NativeBuildOutputDir)\libonnxruntime.dylib; - $(NativeBuildOutputDir)\libonnxruntime_providers_*.dylib; + Include="$(NativeBuildOutputDir)\libonnxruntime_providers_*.dylib; $(NativeBuildOutputDir)\libcustom_op_library*.dylib"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>false</Visible> </None> - <None Include="$(OnnxRuntimeCSharpRoot)\testdata\*"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - <None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\overridable_initializer.onnx"> + <None Include="$(OnnxRuntimeRoot)\csharp\testdata\*"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>false</Visible> </None> - <None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\capi_symbolic_dims.onnx"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - <Visible>false</Visible> - </None> - <None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\custom_op_library\custom_op_test.onnx"> + + <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\custom_op_library\custom_op_test.onnx"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>false</Visible> </None> - <None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\lora\two_params_lora_model.onnx"> + + <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\lora\two_params_lora_model.onnx"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>false</Visible> </None> - <None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\lora\two_params_lora_model.onnx_adapter"> + + <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\lora\two_params_lora_model.onnx_adapter"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>false</Visible> </None> + <BuildEnvVars Include="OnnxRuntimeBuildDirectory=$(OnnxRuntimeBuildDirectory)" /> </ItemGroup> @@ -131,7 +127,7 @@ </ItemGroup> <ItemGroup> - <None Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\training_api\**\*.*"> + <None Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\training_api\**\*.*"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>false</Visible> </None>