Skip to content

Commit a586e05

Browse files
author
Yi Zhang
committed
Revert "Rework the native library usage so that a pre-built ORT native package can be easily used (#22345)"
This reverts commit ba0bb43.
1 parent 6b26ed0 commit a586e05

File tree

8 files changed

+575
-447
lines changed

8 files changed

+575
-447
lines changed

csharp/OnnxRuntime.CSharp.proj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ CMake creates a target to this project
6464
<Error Text="Building via this file is not supported. Please build using the appropriate .sln file in this directory." />
6565
</Target>
6666

67+
<Target Name="RunTest">
68+
<Message Importance="High" Text="Running CSharp tests..." />
69+
<Exec Command="$(DotNetExe) test test\Microsoft.ML.OnnxRuntime.Tests\Microsoft.ML.OnnxRuntime.Tests.csproj -c $(Configuration) --no-build --blame -v n" ConsoleToMSBuild="true">
70+
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
71+
</Exec>
72+
</Target>
73+
6774
<Target Name="ObtainPackageVersion" BeforeTargets="Build;CreatePackage;CreateWindowsAIPackage;CreateNativePackage">
6875
<ReadLinesFromFile File="..\VERSION_NUMBER">
6976
<Output TaskParameter="Lines" ItemName="MajorVersionNumber"/>
@@ -146,7 +153,7 @@ CMake creates a target to this project
146153
<!-- Create Microsoft.ML.OnnxRuntime.Managed with the C# bindings using the C# project -->
147154
<Message Condition="'$(IsPlatformSpecificSubPackage)'!='True'" Importance="High" Text="Creating Microsoft.ML.OnnxRuntime.Managed nuget package..." />
148155
<MSBuild Condition="'$(IsPlatformSpecificSubPackage)'!='True'" Projects="src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj"
149-
Targets="RenameFilesToPack;Pack"
156+
Targets="CopyMiscFiles;Pack"
150157
Properties="NoBuild=true;Platform=AnyCPU;PackageVersion=$(PackageVersion);OrtPackageId=$(OrtPackageId);IncludeMobileTargets=$(IncludeMobileTargets)"/>
151158

152159
<MSBuild Projects ="$(MSBuildProjectFullPath)"

csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj

Lines changed: 184 additions & 88 deletions
Large diffs are not rendered by default.

csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/Microsoft.ML.OnnxRuntime.Tests.Common.csproj

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild>
4-
<IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild>
5-
<IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild>
6-
7-
<OnnxRuntimeRoot>$(ProjectDir)..\..\..</OnnxRuntimeRoot>
8-
</PropertyGroup>
92

103
<PropertyGroup>
114
<!-- netstandard2.0 is used by most platforms. net8.0 is required for linux. -->
125
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
136
<IsPackable>false</IsPackable>
7+
<OnnxRuntimeCsharpRoot>$(ProjectDir)..\..</OnnxRuntimeCsharpRoot>
148
<Platforms>AnyCPU</Platforms>
159
<OutputPath>bin\$(Configuration)\</OutputPath>
16-
<ProtoSrc>$(OnnxRuntimeRoot)\cmake\external\onnx</ProtoSrc>
10+
<IsLinuxBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinuxBuild>
11+
<IsWindowsBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindowsBuild>
12+
<IsMacOSBuild Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOSBuild>
13+
<ProtoSrc>$(OnnxRuntimeCsharpRoot)\..\cmake\external\onnx</ProtoSrc>
1714

1815
<!-- Generated OnnxML.cs triggers this warning. -->
1916
<NoWarn>8981</NoWarn>
@@ -25,22 +22,30 @@
2522
<AssemblyOriginatorKeyFile>..\..\OnnxRuntime.snk</AssemblyOriginatorKeyFile>
2623
<Configurations>Debug;Release;RelWithDebInfo</Configurations>
2724
<!-- end -->
28-
2925
<RootNamespace>Microsoft.ML.OnnxRuntime.Tests</RootNamespace>
3026
<AssemblyName>Microsoft.ML.OnnxRuntime.Tests.Common</AssemblyName>
3127
</PropertyGroup>
3228

33-
<PropertyGroup Condition="'$(IsWindowsBuild)'=='true'">
34-
<ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake\$(Configuration)</ProtocDirectory>
35-
<ProtocExe>$(ProtocDirectory)\protoc.exe</ProtocExe>
36-
</PropertyGroup>
37-
3829
<PropertyGroup Condition="'$(IsLinuxBuild)'=='true'">
30+
<!--internal build related properties for Linux -->
31+
<OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Linux</OnnxRuntimeBuildDirectory>
32+
<NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir>
3933
<ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake</ProtocDirectory>
4034
<ProtocExe>$(ProtocDirectory)\protoc</ProtocExe>
4135
</PropertyGroup>
4236

37+
<PropertyGroup Condition="'$(IsWindowsBuild)'=='true'">
38+
<!--internal build related properties for Windows -->
39+
<OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\Windows</OnnxRuntimeBuildDirectory>
40+
<NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir>
41+
<ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake\$(Configuration)</ProtocDirectory>
42+
<ProtocExe>$(ProtocDirectory)\protoc.exe</ProtocExe>
43+
</PropertyGroup>
44+
4345
<PropertyGroup Condition="'$(IsMacOSBuild)'=='true'">
46+
<!--internal build related properties for OSX -->
47+
<OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">$(OnnxRuntimeCsharpRoot)\..\build\MacOS</OnnxRuntimeBuildDirectory>
48+
<NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir>
4449
<ProtocDirectory Condition="'$(ProtocDirectory)'==''">$(OnnxRuntimeBuildDirectory)\$(Configuration)\external\protobuf\cmake</ProtocDirectory>
4550
<ProtocExe>$(ProtocDirectory)\protoc</ProtocExe>
4651
</PropertyGroup>
@@ -97,6 +102,28 @@
97102
</None>
98103
</ItemGroup>
99104

105+
<!--
106+
Microsoft.ML.OnnxRuntime.Tests.MAUI.csproj handles the native lib coming from a local build or a nuget package so we
107+
don't need to duplicate that logic to include the native lib here.
108+
-->
109+
<ItemGroup Condition="$(SkipNativeLibInclude) != 'true'">
110+
<None Condition="'$(IsWindowsBuild)'=='true'"
111+
Include="$(NativeBuildOutputDir)\onnxruntime.dll;$(NativeBuildOutputDir)\onnxruntime.pdb">
112+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
113+
<Visible>false</Visible>
114+
</None>
115+
116+
<None Condition="'$(IsLinuxBuild)'=='true'" Include="$(NativeBuildOutputDir)\libonnxruntime.so">
117+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
118+
<Visible>false</Visible>
119+
</None>
120+
121+
<None Condition="'$(IsMacOSBuild)'=='true'" Include="$(NativeBuildOutputDir)\libonnxruntime.dylib">
122+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
123+
<Visible>false</Visible>
124+
</None>
125+
</ItemGroup>
126+
100127
<ItemGroup>
101128
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
102129
<PackageReference Include="Google.Protobuf" Version="3.21.12" />
@@ -105,20 +132,16 @@
105132
</ItemGroup>
106133

107134
<ItemGroup>
108-
<ProjectReference Include="$(OnnxRuntimeRoot)\csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" />
135+
<ProjectReference Include="$(OnnxRuntimeCsharpRoot)\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj" />
109136
</ItemGroup>
110137

111138
<!-- generate OnnxMl.cs from ONNX protobuf definition -->
112139
<Target Name="ProtoGen" BeforeTargets="BeforeBuild" Condition="Exists('$(ProtocExe)')">
113-
<Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-ml.proto3"
114-
ContinueOnError="false">
115-
</Exec>
140+
<Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-ml.proto3" ContinueOnError="false"></Exec>
116141
</Target>
117142

118143
<Target Name="ProtoDataGen" BeforeTargets="BeforeBuild" Condition="Exists('$(ProtocExe)')">
119-
<Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-data.proto3"
120-
ContinueOnError="false">
121-
</Exec>
144+
<Exec Command="$(ProtocExe) -I=$(ProtoSrc) --csharp_out=. $(ProtoSrc)\onnx\onnx-data.proto3" ContinueOnError="false"></Exec>
122145
</Target>
123146

124147
<ItemGroup>
@@ -129,20 +152,20 @@
129152
<WriteLinesToFile File="$(OutputPath)\Properties.txt" Lines="@(BuildEnvVars)" Overwrite="true" />
130153
</Target>
131154

132-
<!-- Test Data that is used in MAUI and NetCore test app. Loaded via embedded resource for that to be possible -->
133155
<ItemGroup>
134156
<EmbeddedResource Include="..\..\testdata\*">
135-
<Link>TestData\%(Filename)%(Extension)</Link>
157+
<Link>TestData\%(Filename)%(Extension)</Link>
136158
</EmbeddedResource>
137-
<EmbeddedResource Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\overridable_initializer.onnx">
138-
<Link>TestData\overridable_initializer.onnx</Link>
159+
<EmbeddedResource Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\overridable_initializer.onnx">
160+
<Link>TestData\overridable_initializer.onnx</Link>
139161
</EmbeddedResource>
140-
<EmbeddedResource Include="$(OnnxRuntimeRoot)\onnxruntime\test\testdata\capi_symbolic_dims.onnx">
141-
<Link>TestData\capi_symbolic_dims.onnx</Link>
162+
<EmbeddedResource Include="$(OnnxRuntimeCSharpRoot)\..\onnxruntime\test\testdata\capi_symbolic_dims.onnx">
163+
<Link>TestData\capi_symbolic_dims.onnx</Link>
142164
</EmbeddedResource>
143165
</ItemGroup>
144166

145167
<ItemGroup>
146168
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
147169
</ItemGroup>
170+
148171
</Project>

csharp/test/Microsoft.ML.OnnxRuntime.Tests.Common/NativeLibraryInclude.props

Lines changed: 0 additions & 171 deletions
This file was deleted.

0 commit comments

Comments
 (0)