onnxruntime/csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Microsoft.ML.OnnxRuntime.Tests.Common.csproj
Scott McKay ba0bb43b00
Rework the native library usage so that a pre-built ORT native package can be easily used (#22345)
### Description
The local build of the native library was being included by almost every
project, but is only needed to run tests. Due to the multiple inclusions
attempting to use a pre-built package was clashing with any local builds
that were available.

Create a helper file to include either a local built of a pre-built
package and include that in the two test projects.

Cleanup various miscellaous things.

### Motivation and Context

Create setup to simplify running on-device tests with the nuget
packages.
2024-11-01 11:03:33 -07:00

148 lines
6.6 KiB
XML

<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>
<Platforms>AnyCPU</Platforms>
<OutputPath>bin\$(Configuration)\</OutputPath>
<ProtoSrc>$(OnnxRuntimeRoot)\cmake\external\onnx</ProtoSrc>
<!-- Generated OnnxML.cs triggers this warning. -->
<NoWarn>8981</NoWarn>
<!-- following attributes were necessary for the migrated Tensor tests -->
<LangVersion>default</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly> <!-- need signing for friend access to the internals of the Tensors assembly -->
<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="'$(IsWindowsBuild)'=='true'">
<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'">
<ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake</ProtocDirectory>
<ProtocExe>$(ProtocDirectory)\protoc</ProtocExe>
</PropertyGroup>
<ItemGroup>
<Compile Remove="InferenceTest.cs" />
<Compile Remove="OrtIoBindingAllocationTest.cs" />
<Compile Remove="OrtEnvTests.cs" />
<Compile Remove="OrtValueTests.cs" />
<Compile Remove="OrtFloat16Tests.cs" />
<Compile Remove="Tensors\TensorTests.cs" />
<Compile Remove="TrainingTest.cs" />
</ItemGroup>
<ItemGroup>
<Compile Update="Tensors\TensorArithmetic.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Tensors\TensorArithmetic.tt</DependentUpon>
</Compile>
<Compile Update="Tensors\TensorOperations.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Tensors\TensorOperations.tt</DependentUpon>
</Compile>
<Compile Update="Tensors\TensorArithmetic.cs">
<DependentUpon>TensorArithmetic.tt</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Compile Update="Tensors\TensorOperations.cs">
<DependentUpon>TensorOperations.tt</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
</ItemGroup>
<ItemGroup>
<!-- include common files for visibility, however they're compiled directly by the target specific test projects -->
<None Include="InferenceTest.cs" />
<None Include="OnnxData.cs" />
<None Include="OrtIoBindingAllocationTest.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
<None Include="OrtValueTests.cs" />
<None Include="OrtFloat16Tests.cs" />
<None Include="Tensors\TensorTests.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
<None Include="Tensors\ArrayTensorExtensionTests.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
<None Include="TrainingTest.cs" />
</ItemGroup>
<ItemGroup>
<None Update="Tensors\TensorArithmetic.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>TensorArithmetic.cs</LastGenOutput>
</None>
<None Update="Tensors\TensorOperations.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>TensorOperations.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Google.Protobuf" Version="3.21.12" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<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>
</Target>
<Target Name="ProtoDataGen" BeforeTargets="BeforeBuild" Condition="Exists('$(ProtocExe)')">
<Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-data.proto3"
ContinueOnError="false">
</Exec>
</Target>
<ItemGroup>
<BuildEnvVars Include="OnnxRuntimeBuildDirectory=$(OnnxRuntimeBuildDirectory)" />
</ItemGroup>
<Target Name="DefineBuildEnvironmentVariables" BeforeTargets="Build">
<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>
</EmbeddedResource>
<EmbeddedResource Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\overridable_initializer.onnx">
<Link>TestData\overridable_initializer.onnx</Link>
</EmbeddedResource>
<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>