diff --git a/csharp/OnnxRuntime.CSharp.proj b/csharp/OnnxRuntime.CSharp.proj
index 2ba184601c..94635f2dc3 100644
--- a/csharp/OnnxRuntime.CSharp.proj
+++ b/csharp/OnnxRuntime.CSharp.proj
@@ -40,43 +40,8 @@ CMake creates a target to this project
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -86,7 +51,7 @@ CMake creates a target to this project
-
+
@@ -122,7 +87,7 @@ CMake creates a target to this project
+ Properties="NoBuild=true;Platform=AnyCPU;PackageVersion=$(PackageVersion);OrtPackageId=$(OrtPackageId);SelectedTargets=All"/>
diff --git a/csharp/readme.md b/csharp/readme.md
new file mode 100644
index 0000000000..ad71348b29
--- /dev/null
+++ b/csharp/readme.md
@@ -0,0 +1,70 @@
+# ORT C# Managed Library
+
+The solution files here are used to produce nuget packages for the C# bindings.
+
+Note that the project naming is currently confusing and needs updating.
+
+ - The Microsoft.ML.OnnxRuntime project produces the Microsoft.ML.OnnxRuntime.**Managed** nuget package.
+ - The Microsoft.ML.OnnxRuntime nuget package contains the native (i.e. C++) code for various platforms.
+
+## Solution files
+
+The main solution file is OnnxRuntime.CSharp.sln. This includes desktop and Xamarin mobile projects.
+OnnxRuntime.DesktopOnly.CSharp.sln is a copy of that with all the mobile projects removed. This is
+due to there being no way to selectively exclude a csproj from the sln if Xamarin isn't available.
+
+If changes are required, either update the main solution first and copy the relevant changes across,
+or copy the entire file and remove the mobile projects (anything with iOS, Android or Droid in the name).
+
+## Development setup:
+
+### Requirements:
+
+NOTE: The usage of this solution is primarily for ORT developers creating the managed Microsoft.ML.OnnxRuntime.Managed
+ nuget package. Due to that, the requirements are quite specific.
+
+Visual Studio 2022 v17.2.4 or later, with Xamarin workloads
+ - v17.2.4 installs dotnet sdk 6.0.301
+ - in theory you could use an earlier VS version and download dotnet SDK 6.0.300+ from https://dotnet.microsoft.com/en-us/download/dotnet/6.0
+ - untested
+
+There's no good way to use Visual Studio 2022 17.3 Preview in a CI, so we currently have to build pre-.net6 targets
+using VS, and .net6 targets using dotnet. We can't build them all using dotnet as the xamarin targets require msbuild.
+We can't package them using dotnet as that also requires msbuild.
+
+Once the official VS 2022 release supports .net6 and is available in the CI we can revert to the original simple
+setup of building everything using msbuild.
+
+To test packaging locally you will also need nuget.exe.
+Download from https://www.nuget.org/downloads.
+Put in a folder (e.g. C:\Program Files (x86)\NuGet).
+Add that folder to your PATH.
+
+### Magic incantations to build the nuget managed package locally:
+
+If we're starting with VS 2022 17.2.4 we should have dotnet sdk 6.0.301
+
+Make sure all the required workloads are installed
+ `dotnet workload install android ios maccatalyst macos`
+ - original example from [here](https://github.com/Sweekriti91/maui-samples/blob/swsat/devops/6.0/Apps/WeatherTwentyOne/devops/AzureDevOps/azdo_windows.yml):
+ - `dotnet workload install android ios maccatalyst macos maui --source https://aka.ms/dotnet6/nuget/index.json --source https://api.nuget.org/v3/index.json`
+ - don't need 'maui' in this list until we update the sample/test apps
+ - didn't seem to need --source arg/s for local build. YMMV.
+
+Build pre-net6 targets
+ `msbuild -t:restore .\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj -p:SelectedTargets=PreNet6`
+ `msbuild -t:build .\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj -p:SelectedTargets=PreNet6`
+
+ Need to run msbuild twice - once to restore which creates some json configs that are needed like
+ Microsoft.ML.OnnxRuntime\obj\project.assets.json, and once to build using the configs.
+
+Build net6 targets
+ `dotnet build .\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj -p:SelectedTargets=Net6`
+
+ The dotnet build does the restore internally.
+
+Create project.assets.json in obj dir with all targets so the nuget package creation includes them all
+ `msbuild -t:restore .\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj -p:SelectedTargets=All`
+
+Create nuget package
+ `msbuild .\OnnxRuntime.CSharp.proj -t:CreatePackage -p:OrtPackageId=Microsoft.ML.OnnxRuntime -p:Configuration=Debug -p:Platform="Any CPU"`
diff --git a/csharp/sample/InferenceSample/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS.csproj b/csharp/sample/InferenceSample/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS.csproj
index 31e0fd2d12..ce261096c1 100644
--- a/csharp/sample/InferenceSample/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS.csproj
+++ b/csharp/sample/InferenceSample/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS/Microsoft.ML.OnnxRuntime.InferenceSample.Forms.iOS.csproj
@@ -17,7 +17,7 @@
automatic
- True
+ True
true
@@ -67,11 +67,11 @@
SdkOnly
- ..\..\..\..\build\iOS\iphoneos\Release\Release-iphoneos\onnxruntime.framework
- ..\..\..\..\build\iOS\iphonesimulator\Release\Release-iphonesimulator\onnxruntime.framework
+ ..\..\..\..\build\iOS\iphoneos\Release\Release-iphoneos\onnxruntime.framework
+ ..\..\..\..\build\iOS\iphonesimulator\Release\Release-iphonesimulator\onnxruntime.framework
- __NATIVE_DEPENDENCIES_EXIST__
+ __NATIVE_DEPENDENCIES_EXIST__
@@ -147,17 +147,17 @@
-
-
- Framework
- True
- True
-
-
- Framework
- True
- True
-
+
+
+ Framework
+ True
+ True
+
+
+ Framework
+ True
+ True
+
\ No newline at end of file
diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/AssemblyInfo.shared.cs b/csharp/src/Microsoft.ML.OnnxRuntime/AssemblyInfo.shared.cs
index 4e3ef20ab0..68a9bf4a05 100644
--- a/csharp/src/Microsoft.ML.OnnxRuntime/AssemblyInfo.shared.cs
+++ b/csharp/src/Microsoft.ML.OnnxRuntime/AssemblyInfo.shared.cs
@@ -1,8 +1,17 @@
+#if __XAMARIN__
#if __IOS__
[assembly: Foundation.LinkerSafe]
#elif __ANDROID__
[assembly: Android.LinkerSafe]
#endif
+#else
+// .net 6
+#if __IOS__
+[assembly: System.Reflection.AssemblyMetadata ("IsTrimmable", "True")]
+#elif __ANDROID__
+[assembly: global::System.Reflection.AssemblyMetadata("IsTrimmable", "True")]
+#endif
+#endif
// Making these assembly's internals visible to the internal Test assembly
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Microsoft.ML.OnnxRuntime.Tests.Common, PublicKey=002400000480000094000000060200000024000052534131000400000100010059013e94e4bc70136ca4c35f33acd6b62974536b698f9c7a21cee18d805c7ad860ad9eebfdc47a96ba2f8d03f4cf1c36b9d30787e276c7b9833b5bf2a6eba7e919e6b90083078a352262aed1d842e5f70a3085cbcf4c56ae851b161137920961c23fcc246598d61d258ccc615c927b2441359eea666a99ce1c3c07dca18fb0e1")]
diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj
index 2c484fb251..3711978cff 100644
--- a/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj
+++ b/csharp/src/Microsoft.ML.OnnxRuntime/Microsoft.ML.OnnxRuntime.csproj
@@ -4,21 +4,56 @@
Microsoft.ML.OnnxRuntime
-
-
-
-
- netstandard1.1;netstandard2.0;xamarinios10;monoandroid11.0;net5.0;netcoreapp3.1
-
-
-
-
- netstandard1.1;netstandard2.0;net5.0;netcoreapp3.1
-
-
-
+
+
+ PreNet6
+ netstandard1.1;netstandard2.0;net5.0;netcoreapp3.1
+
+
+
+
+ xamarinios10;monoandroid11.0
+
+
+
+
+ net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst;net6.0-macos
+
+
+
+ $(BaseTargets);$(XamarinTargets)
+
+
+
+ $(Net6Targets)
+
+
+
+
+ $(BaseTargets);$(XamarinTargets);$(Net6Targets)
+
+
+
AnyCPU;x86
7.2
@@ -70,37 +105,92 @@
true
true
true
+
+
+ true
+ true
+ true
+ true
-
-
- $(OnnxRuntimeCsharpRoot)\..\build\Linux
- $(OnnxRuntimeBuildDirectory)\$(Configuration)
-
+
+
+
+ $(OnnxRuntimeCsharpRoot)\..\build\Linux
+ $(OnnxRuntimeBuildDirectory)\$(Configuration)
+
-
-
- $(OnnxRuntimeCsharpRoot)\..\build\Windows
- $(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)
-
+
+
+ $(OnnxRuntimeCsharpRoot)\..\build\Windows
+ $(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)
+
-
-
- $(OnnxRuntimeCsharpRoot)\..\build\MacOS
- $(OnnxRuntimeBuildDirectory)\$(Configuration)
-
+
+
+ $(OnnxRuntimeCsharpRoot)\..\build\MacOS
+ $(OnnxRuntimeBuildDirectory)\$(Configuration)
+
-
- __IOS__;__MOBILE__;
-
+
+
+ $(OrtConstants);__MOBILE__
+
-
- __ANDROID__;__MOBILE__;
-
+
+ $(OrtConstants);__ANDROID__
+
-
- __NETCOREAPP_NETFRAMEWORK__;
-
+
+ $(OrtConstants);__IOS__
+
+
+
+
+ $(OrtConstants);__ENABLE_COREML__
+
+
+
+
+ $(OrtConstants);__ENABLE_COREML__
+
+
+
+ $(OrtConstants);__XAMARIN__
+
+
+
+ $(DefineConstants);$(OrtConstants)
+
+
+
/// Create OrtIoBinding instance that is used to bind memory that is allocated
@@ -1371,9 +1373,9 @@ namespace Microsoft.ML.OnnxRuntime
public static DOrtSetLanguageProjection OrtSetLanguageProjection;
- #endregion IoBinding API
+#endregion IoBinding API
- #region ModelMetadata API
+#region ModelMetadata API
///
/// Gets the ModelMetadata associated with an InferenceSession
@@ -1492,9 +1494,9 @@ namespace Microsoft.ML.OnnxRuntime
public static DOrtReleaseModelMetadata OrtReleaseModelMetadata;
- #endregion ModelMetadata API
+#endregion ModelMetadata API
- #region Tensor/OnnxValue API
+#region Tensor/OnnxValue API
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate IntPtr /*(OrtStatus*)*/ DOrtGetValue(IntPtr /*(OrtValue*)*/ value,
@@ -1651,9 +1653,9 @@ namespace Microsoft.ML.OnnxRuntime
public static DOrtReleaseValue OrtReleaseValue;
- #endregion
+#endregion
- #region Misc API
+#region Misc API
///
/// Queries all the execution providers supported in the native onnxruntime shared library
@@ -1693,7 +1695,7 @@ namespace Microsoft.ML.OnnxRuntime
public static DOrtReleasePrepackedWeightsContainer OrtReleasePrepackedWeightsContainer;
- #endregion
+#endregion
public static byte[] GetPlatformSerializedString(string str)
{
diff --git a/csharp/src/Microsoft.ML.OnnxRuntime/SessionOptions.shared.cs b/csharp/src/Microsoft.ML.OnnxRuntime/SessionOptions.shared.cs
index 012c7223ab..944ded201a 100644
--- a/csharp/src/Microsoft.ML.OnnxRuntime/SessionOptions.shared.cs
+++ b/csharp/src/Microsoft.ML.OnnxRuntime/SessionOptions.shared.cs
@@ -337,8 +337,8 @@ namespace Microsoft.ML.OnnxRuntime
NativeApiStatus.VerifySuccess(
NativeMethods.OrtSessionOptionsAppendExecutionProvider_CoreML(handle, (uint)coremlFlags));
#else
-#if !__ANDROID__
- // the CoreML EP entry point is registered unless this is Android but is only valid if this is OSX
+#if __ENABLE_COREML__
+ // only attempt if this is OSX
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
NativeApiStatus.VerifySuccess(
diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.iOS/Microsoft.ML.OnnxRuntime.Tests.iOS.csproj b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.iOS/Microsoft.ML.OnnxRuntime.Tests.iOS.csproj
index 4b0e9b691f..6df666f25c 100644
--- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests.iOS/Microsoft.ML.OnnxRuntime.Tests.iOS.csproj
+++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests.iOS/Microsoft.ML.OnnxRuntime.Tests.iOS.csproj
@@ -1,221 +1,208 @@
-
- Debug
- iPhoneSimulator
- {19446672-EBA3-4BA6-8DFB-AB2A85AC9AA4}
- {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- {edc1b0fa-90cd-4038-8fad-98fe74adb368}
- Exe
- Microsoft.ML.OnnxRuntime.Tests.iOS
- Microsoft.ML.OnnxRuntime.Tests.iOS
- Resources
- true
- NSUrlSessionHandler
- PackageReference
- automatic
- true
- ..\..\OnnxRuntime.snk
-
-
-
- True
- --nowarn:0109
- CS8002
-
-
-
- true
- portable
- false
- bin\iPhoneSimulator\Debug
- DEBUG
- prompt
- 4
- x86_64
- None
- true
- true
-
-
-
- none
- true
- bin\iPhoneSimulator\Release
- prompt
- 4
- None
- x86_64
- true
-
-
-
- true
- portable
- false
- bin\iPhone\Debug
- DEBUG
- prompt
- 4
- ARM64
- Entitlements.plist
- iPhone Developer
- true
- SdkOnly
- true
-
-
-
- none
- true
- bin\iPhone\Release
- prompt
- 4
- Entitlements.plist
- ARM64
- iPhone Distribution
- Full
- true
- true
- --nowarn:0109 --linkskip=Microsoft.ML.OnnxRuntime.Tests.iOS --linkskip=Microsoft.ML.OnnxRuntime.Tests.Common --linkskip=Microsoft.ML.OnnxRuntime.Tests.Devices
-
-
-
- ..\..\..\build\iOS\iphoneos\Release\Release-iphoneos\onnxruntime.framework
- ..\..\..\build\iOS\iphonesimulator\Release\Release-iphonesimulator\onnxruntime.framework
-
-
-
- __NATIVE_DEPENDENCIES_EXIST__
-
-
-
-
-
-
-
-
-
-
-
-
- 2.5.25
-
-
- 2.4.1
-
-
-
- 5.0.0.2083
-
-
-
- 0.22.2
-
-
-
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- InferenceTest.cs
-
-
- OrtIoBindingAllocationTest.cs
-
-
- TensorTests.cs
-
-
-
- {584B53B3-359D-4DC2-BCD8-530B5D4685AD}
- Microsoft.ML.OnnxRuntime
-
-
-
-
-
- Framework
- True
- True
-
-
- Framework
- True
- True
-
-
-
-
-
- {04FA49F0-AA23-4EE5-B455-6E12FFAD29E6}
- Microsoft.ML.OnnxRuntime.Tests.Common
-
-
- {30431891-3929-4394-8049-75055B92315F}
- Microsoft.ML.OnnxRuntime.Tests.Devices
-
-
-
+
+ Debug
+ iPhoneSimulator
+ {19446672-EBA3-4BA6-8DFB-AB2A85AC9AA4}
+ {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ {edc1b0fa-90cd-4038-8fad-98fe74adb368}
+ Exe
+ Microsoft.ML.OnnxRuntime.Tests.iOS
+ Microsoft.ML.OnnxRuntime.Tests.iOS
+ Resources
+ true
+ NSUrlSessionHandler
+ PackageReference
+ automatic
+
+ true
+ ..\..\OnnxRuntime.snk
+
+
+ True
+ --nowarn:0109
+ CS8002
+
+
+ true
+ portable
+ false
+ bin\iPhoneSimulator\Debug
+ DEBUG
+ prompt
+ 4
+ x86_64
+ None
+ true
+ true
+
+
+ none
+ true
+ bin\iPhoneSimulator\Release
+ prompt
+ 4
+ None
+ x86_64
+ true
+
+
+ true
+ portable
+ false
+ bin\iPhone\Debug
+ DEBUG
+ prompt
+ 4
+ ARM64
+ Entitlements.plist
+ iPhone Developer
+ true
+ SdkOnly
+ true
+
+
+ none
+ true
+ bin\iPhone\Release
+ prompt
+ 4
+ Entitlements.plist
+ ARM64
+ iPhone Distribution
+ Full
+ true
+ true
+ --nowarn:0109 --linkskip=Microsoft.ML.OnnxRuntime.Tests.iOS --linkskip=Microsoft.ML.OnnxRuntime.Tests.Common --linkskip=Microsoft.ML.OnnxRuntime.Tests.Devices
+
+
+ ..\..\..\build\iOS\iphoneos\Release\Release-iphoneos\onnxruntime.framework
+ ..\..\..\build\iOS\iphonesimulator\Release\Release-iphonesimulator\onnxruntime.framework
+
+
+ __NATIVE_DEPENDENCIES_EXIST__
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2.5.25
+
+
+ 2.4.1
+
+
+
+ 5.0.0.2083
+
+
+
+ 0.22.2
+
+
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ InferenceTest.cs
+
+
+ OrtIoBindingAllocationTest.cs
+
+
+ TensorTests.cs
+
+
+
+ {584B53B3-359D-4DC2-BCD8-530B5D4685AD}
+ Microsoft.ML.OnnxRuntime
+
+
+
+
+ Framework
+ True
+ True
+
+
+ Framework
+ True
+ True
+
+
+
+
+ {04FA49F0-AA23-4EE5-B455-6E12FFAD29E6}
+ Microsoft.ML.OnnxRuntime.Tests.Common
+
+
+ {30431891-3929-4394-8049-75055B92315F}
+ Microsoft.ML.OnnxRuntime.Tests.Devices
+
+
+
\ No newline at end of file
diff --git a/tools/ci_build/github/azure-pipelines/c-api-noopenmp-packaging-pipelines.yml b/tools/ci_build/github/azure-pipelines/c-api-noopenmp-packaging-pipelines.yml
index 44fe22f3cf..9653544a97 100644
--- a/tools/ci_build/github/azure-pipelines/c-api-noopenmp-packaging-pipelines.yml
+++ b/tools/ci_build/github/azure-pipelines/c-api-noopenmp-packaging-pipelines.yml
@@ -423,7 +423,9 @@ jobs:
- job: NuGet_Packaging_GPU
workspace:
clean: all
- pool: 'Win-CPU-2021'
+ # we need to use the 2022 pool to create the nuget package with both pre-net6+Xamarin and net6 targets.
+ # VS2019 has no support for net6 and we need to use msbuild (from the VS install) to do the packing
+ pool: 'Azure-Pipelines-EO-Windows2022-aiinfra'
variables:
breakCodesignValidationInjection: ${{ parameters.DoEsrp }}
dependsOn:
@@ -465,7 +467,7 @@ jobs:
artifactName: 'drop-extra'
targetPath: '$(Build.BinariesDirectory)/extra-artifact'
- #Reconstruct the build dir
+ # Reconstruct the build dir
- task: PowerShell@2
displayName: 'PowerShell Script'
inputs:
@@ -487,22 +489,45 @@ jobs:
inputs:
versionSpec: 5.7.0
- - task: MSBuild@1
- displayName: 'Restore NuGet Packages'
+ - task: PowerShell@2
+ displayName: Install .NET 6 workloads
inputs:
- solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
- platform: 'Any CPU'
- configuration: RelWithDebInfo
- msbuildArguments: '-t:restore -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu"'
+ targetType: 'inline'
+ script: |
+ dotnet workload install android ios maccatalyst macos
+ workingDirectory: '$(Build.SourcesDirectory)\csharp'
+
+ - task: PowerShell@2
+ displayName: Build .NET 6 targets using dotnet
+ inputs:
+ targetType: 'inline'
+ # we don't specify 'Any CPU' as the platform here because if we do it gets added to the output path
+ # e.g. csharp\src\Microsoft.ML.OnnxRuntime\bin\Any CPU\RelWithDebInfo\net6.0-ios\
+ # which is inconsistent with the msbuild output path for the pre-.net6 targets
+ # e.g. csharp\src\Microsoft.ML.OnnxRuntime\bin\RelWithDebInfo\monoandroid11.0
+ # and makes it harder to do the packing
+ #
+ # 'Any CPU' is the default (first 'mixed' platform specified in the csproj) so this should be fine.
+ script: |
+ dotnet build .\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj -p:SelectedTargets=Net6 -p:Configuration=RelWithDebInfo -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu" -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
- displayName: 'Build C#'
+ displayName: 'Restore NuGet Packages and create project.assets.json for pre-.net6 targets'
+ inputs:
+ solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
+ platform: 'Any CPU'
+ configuration: RelWithDebInfo
+ msbuildArguments: '-t:restore -p:SelectedTargets=PreNet6 -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu"'
+ workingDirectory: '$(Build.SourcesDirectory)\csharp'
+
+ - task: MSBuild@1
+ displayName: 'Build C# for pre-.net6 targets'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
configuration: RelWithDebInfo
platform: 'Any CPU'
- msbuildArguments: '-p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu" -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}'
+ msbuildArguments: '-p:SelectedTargets=PreNet6 -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu" -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- template: templates/win-esrp-dll.yml
@@ -511,6 +536,15 @@ jobs:
DisplayName: 'ESRP - Sign C# dlls'
DoEsrp: ${{ parameters.DoEsrp }}
+ - task: MSBuild@1
+ displayName: Update projects.assets.json will combined list of all target frameworks
+ inputs:
+ solution: '$(Build.SourcesDirectory)\csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj'
+ platform: 'Any CPU'
+ configuration: RelWithDebInfo
+ msbuildArguments: '-t:restore -p:SelectedTargets=All -p:OrtPackageId=Microsoft.ML.OnnxRuntime.Gpu'
+ workingDirectory: '$(Build.SourcesDirectory)\csharp'
+
- task: MSBuild@1
displayName: 'Build Nuget Packages'
inputs:
@@ -582,7 +616,7 @@ jobs:
displayName: 'Run Roslyn Analyzers'
inputs:
userProvideBuildInfo: msBuildInfo
- msBuildCommandline: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" $(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln -p:configuration="RelWithDebInfo" -p:Platform="Any CPU" -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=Microsoft.ML.OnnxRuntime.Gpu'
+ msBuildCommandline: '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild.exe" $(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln -p:configuration="RelWithDebInfo" -p:Platform="Any CPU" -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=Microsoft.ML.OnnxRuntime.Gpu'
condition: and(succeeded(), eq('${{ parameters.DoCompliance }}', true))
- template: templates/component-governance-component-detection-steps.yml
diff --git a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml
index 43064c0cef..860d80bf5d 100644
--- a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml
+++ b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml
@@ -325,7 +325,9 @@ jobs:
- job: NuGet_Packaging_CPU
workspace:
clean: all
- pool: 'Win-CPU-2021'
+ # we need to use the 2022 pool to create the nuget package with both pre-net6+Xamarin and net6 targets.
+ # VS2019 has no support for net6 and we need to use msbuild (from the VS install) to do the packing
+ pool: 'Azure-Pipelines-EO-Windows2022-aiinfra'
variables:
OrtPackageId: ${{ parameters.OrtNugetPackageId }}
breakCodesignValidationInjection: ${{ parameters.DoEsrp }}
@@ -409,7 +411,7 @@ jobs:
workingDirectory: '$(Build.BinariesDirectory)/nuget-artifact'
displayName: 'List artifacts'
- #Reconstruct the build dir
+ # Reconstruct the build dir
- task: PowerShell@2
displayName: 'Extract native libraries for addition to nuget native package'
inputs:
@@ -425,22 +427,45 @@ jobs:
inputs:
versionSpec: 5.7.0
- - task: MSBuild@1
- displayName: 'Restore NuGet Packages'
+ - task: PowerShell@2
+ displayName: Install .NET 6 workloads
inputs:
- solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
- platform: 'Any CPU'
- configuration: RelWithDebInfo
- msbuildArguments: '-t:restore -p:OrtPackageId=$(OrtPackageId)'
+ targetType: 'inline'
+ script: |
+ dotnet workload install android ios maccatalyst macos
+ workingDirectory: '$(Build.SourcesDirectory)\csharp'
+
+ - task: PowerShell@2
+ displayName: Build Microsoft.ML.OnnxRuntime .NET 6 targets using dotnet
+ inputs:
+ targetType: 'inline'
+ # we don't specify 'Any CPU' as the platform here because if we do it gets added to the output path
+ # e.g. csharp\src\Microsoft.ML.OnnxRuntime\bin\Any CPU\RelWithDebInfo\net6.0-ios\
+ # which is inconsistent with the msbuild output path for the pre-.net6 targets
+ # e.g. csharp\src\Microsoft.ML.OnnxRuntime\bin\RelWithDebInfo\monoandroid11.0
+ # and makes it harder to do the packing
+ #
+ # 'Any CPU' is the default (first 'mixed' platform specified in the csproj) so this should be fine.
+ script: |
+ dotnet build .\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj -p:SelectedTargets=Net6 -p:Configuration=RelWithDebInfo -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId) -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
- displayName: 'Build C#'
+ displayName: 'Restore NuGet Packages and create project.assets.json for pre-.net6 targets'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
platform: 'Any CPU'
configuration: RelWithDebInfo
- msbuildArguments: '-p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId) -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}'
+ msbuildArguments: '-t:restore -p:SelectedTargets=PreNet6 -p:OrtPackageId=$(OrtPackageId)'
+ workingDirectory: '$(Build.SourcesDirectory)\csharp'
+
+ - task: MSBuild@1
+ displayName: 'Build C# for pre-.net6 targets'
+ inputs:
+ solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
+ platform: 'Any CPU'
+ configuration: RelWithDebInfo
+ msbuildArguments: '-p:SelectedTargets=PreNet6 -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId) -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- template: win-esrp-dll.yml
@@ -449,6 +474,15 @@ jobs:
DisplayName: 'ESRP - Sign C# dlls'
DoEsrp: ${{ parameters.DoEsrp }}
+ - task: MSBuild@1
+ displayName: Update projects.assets.json will combined list of all target frameworks
+ inputs:
+ solution: '$(Build.SourcesDirectory)\csharp\src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj'
+ platform: 'Any CPU'
+ configuration: RelWithDebInfo
+ msbuildArguments: '-t:restore -p:SelectedTargets=All -p:OrtPackageId=$(OrtPackageId)'
+ workingDirectory: '$(Build.SourcesDirectory)\csharp'
+
- task: MSBuild@1
displayName: 'Build Nuget Packages'
inputs:
@@ -513,7 +547,7 @@ jobs:
displayName: 'Run Roslyn Analyzers'
inputs:
userProvideBuildInfo: msBuildInfo
- msBuildCommandline: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" $(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln -p:configuration="RelWithDebInfo" -p:Platform="Any CPU" -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId)'
+ msBuildCommandline: '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild.exe" $(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln -p:configuration="RelWithDebInfo" -p:Platform="Any CPU" -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId)'
condition: and(succeeded(), eq('${{ parameters.DoCompliance }}', true))
- template: component-governance-component-detection-steps.yml