Rework/cleanup the C# build infrastructure for nuget packages. (#18127)

### Description
Update the C# nuget build infrastructure to make building a test nuget
package more user friendly and to simplify
- Remove usage of dotnet and msbuild in CIs
- was temporary requirement until .net 6 MAUI was added to the released
Visual Studio
  - remove SelectedTargets property and its usage
- Add property for excluding mobile targets
  -  generally we exclude based on the nuget package name
- can now specify `/p:IncludeMobileTargets=false` on the command line to
force exclusion
- support building test package using build.py `--build_nuget` better
- limit inclusion of xamarin targets as building with them requires a
lot more infrastructure
- use msbuild directly if xamarin targets are included. use dotnet
otherwise.
- remove quoting of property values as it doesn't appear to be necessary
and breaks when msbuild is being used
- add infrastructure to be able to pack the nuget package on linux with
`dotnet pack`
    - `nuget pack` is not user friendly as-per comments in changes
    - requires stub csproj to provide the nuspec path 
- Remove netstandard1.0 targets from nuspec
  - we removed support from the actual bindings previously
- Remove usage of nuget-staging directory when creating nuget package on
linux
- the nuspec file element has a fully qualified path for a source file
so there is no obvious benefit to copying to a staging directory prior
to packing

### Motivation and Context
Address issues with 1P users trying to create test nuget packages
locally.
Long overdue cleanup of CI complexity.
This commit is contained in:
Scott McKay 2023-11-04 02:05:17 +10:00 committed by GitHub
parent 4f2096be38
commit c352e9b1f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 179 additions and 212 deletions

View file

@ -17,9 +17,13 @@ CMake creates a target to this project
<TargetArchitecture Condition=" '$(TargetArchitecture)' == '' ">x64</TargetArchitecture>
<IsReleaseBuild Condition=" '$(IsReleaseBuild)' == '' ">false</IsReleaseBuild>
<ReleaseVersionSuffix></ReleaseVersionSuffix>
<IsLinuxBuild Condition=" '$(IsLinuxBuild)' == '' ">false</IsLinuxBuild>
<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>
<ExecutionProvider Condition=" '$(ExecutionProvider)' == '' ">None</ExecutionProvider>
<!-- include Xamarin/MAUI Android and iOS target frameworks? Command line property overrides this value. -->
<IncludeMobileTargets>true</IncludeMobileTargets>
<!--internal build related properties-->
<OnnxRuntimeSourceDirectory Condition="'$(OnnxRuntimeSourceDirectory)'==''">..</OnnxRuntimeSourceDirectory>
<GenerateNuspecScript>..\tools\nuget\generate_nuspec_for_native_nuget.py</GenerateNuspecScript>
@ -30,13 +34,15 @@ CMake creates a target to this project
<OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">..\build\Linux</OnnxRuntimeBuildDirectory>
<OnnxRuntimePackagesDirectory Condition="'$(OnnxRuntimePackagesDirectory)'==''">$(OnnxRuntimeBuildDirectory)\packages</OnnxRuntimePackagesDirectory>
<NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)</NativeBuildOutputDir>
<PythonExe>python3</PythonExe>
</PropertyGroup>
<PropertyGroup Condition="'$(IsLinuxBuild)'=='false'">
<PropertyGroup Condition="'$(IsWindowsBuild)'=='true'">
<!--internal build related properties for Windows -->
<OnnxRuntimeBuildDirectory Condition="'$(OnnxRuntimeBuildDirectory)'==''">..\build\Windows</OnnxRuntimeBuildDirectory>
<OnnxRuntimePackagesDirectory Condition="'$(OnnxRuntimePackagesDirectory)'==''">$(OnnxRuntimeBuildDirectory)\packages</OnnxRuntimePackagesDirectory>
<NativeBuildOutputDir>$(OnnxRuntimeBuildDirectory)\$(Configuration)\$(Configuration)</NativeBuildOutputDir>
<PythonExe>python</PythonExe>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
@ -86,28 +92,48 @@ CMake creates a target to this project
</Target>
<Target Name="CreatePackage">
<Message Importance="High" Text="Bundling managed assemblies into a NuGet package ..." />
<!-- Create Microsoft.ML.OnnxRuntime.Managed with the C# bindings using the C# project -->
<Message Importance="High" Text="Creating Microsoft.ML.OnnxRuntime.Managed nuget package..." />
<MSBuild Projects="src\Microsoft.ML.OnnxRuntime\Microsoft.ML.OnnxRuntime.csproj"
Targets="CopyMiscFiles;Pack"
Properties="NoBuild=true;Platform=AnyCPU;PackageVersion=$(PackageVersion);OrtPackageId=$(OrtPackageId);SelectedTargets=All"/>
Properties="NoBuild=true;Platform=AnyCPU;PackageVersion=$(PackageVersion);OrtPackageId=$(OrtPackageId);IncludeMobileTargets=$(IncludeMobileTargets)"/>
<Message Importance="High" Text="Generating nuspec for the native Nuget package ..." />
<Exec ContinueOnError="False" Command="python $(GenerateNuspecScript) --package_version $(PackageVersion) --package_name $(OrtPackageId) --target_architecture $(TargetArchitecture) --build_config $(Configuration) --native_build_path $(NativeBuildOutputDirAbs) --packages_path $(OnnxRuntimePackagesDirectoryAbs) --ort_build_path $(OnnxRuntimeBuildDirectoryAbs) --sources_path $(OnnxRuntimeSourceDirectoryAbs) --commit_id $(GitCommitHash) --is_release_build $(IsReleaseBuild) --execution_provider $(ExecutionProvider)" ConsoleToMSBuild="true">
<!-- Manually create the nuspec for the native Microsoft.ML.OnnxRuntime package -->
<Message Importance="High" Text="Generating nuspec for the native Microsoft.ML.OnnxRuntime nuget package..." />
<Exec Command="$(PythonExe) $(GenerateNuspecScript) --package_version $(PackageVersion) --package_name $(OrtPackageId) --target_architecture $(TargetArchitecture) --build_config $(Configuration) --native_build_path $(NativeBuildOutputDirAbs) --packages_path $(OnnxRuntimePackagesDirectoryAbs) --ort_build_path $(OnnxRuntimeBuildDirectoryAbs) --sources_path $(OnnxRuntimeSourceDirectoryAbs) --commit_id $(GitCommitHash) --is_release_build $(IsReleaseBuild) --execution_provider $(ExecutionProvider)"
ContinueOnError="False"
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GenerateNuspecOutput" />
</Exec>
<Message Importance="High" Text="Bundling native shared library artifacts into a NuGet package ..." />
<Exec ContinueOnError="False" Command="$(NugetExe) pack NativeNuget.nuspec" ConsoleToMSBuild="true" WorkingDirectory="$(NativeBuildOutputDirAbs)" Condition=" '$(OS)' == 'Windows_NT'">
<!-- run `nuget pack` on Windows or `dotnet pack` on Linux to create the native nupkg -->
<Message Importance="High" Text="Bundling native shared library artifacts into Microsoft.ML.OnnxRuntime nuget package..." />
<Exec Condition=" '$(IsWindowsBuild)' == 'true'"
Command="$(NugetExe) pack NativeNuget.nuspec"
WorkingDirectory="$(NativeBuildOutputDirAbs)"
ContinueOnError="False"
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
<Exec ContinueOnError="False" Command="$(NugetExe) pack NativeNuget.nuspec" ConsoleToMSBuild="true" WorkingDirectory="$(NativeBuildOutputDirAbs)" Condition=" '$(OS)' != 'Windows_NT'">
<!-- build.py uses dotnet to build on linux so we know it's available.
nuget needs to be run using mono to work correctly, but installing mono on WSL breaks interop
(see https://github.com/microsoft/WSL/issues/8531). in order to play nicely with both we use `dotnet pack`
to pack the native nuget package using a stub csproj to provide the nuspec file path.
-->
<Exec Condition="'$(IsLinuxBuild)' == 'true'"
Command="dotnet pack tools/linux_pack/LinuxPackNativeNuget.csproj /p:Configuration=$(Configuration) /p:OnnxRuntimeBuildDirectory=$(NativeBuildOutputDirAbs)"
ContinueOnError="False"
ConsoleToMSBuild="true" >
<Output TaskParameter="ConsoleOutput" PropertyName="OutputOfExec" />
</Exec>
<!-- copy the nupkg to the build output directory so its location is consistent on all platforms -->
<Copy Condition="'$(IsLinuxBuild)' == 'true'"
SourceFiles="tools/linux_pack/bin/$(Configuration)/$(OrtPackageId).$(PackageVersion).nupkg"
DestinationFolder="$(NativeBuildOutputDirAbs)" />
<Copy
SourceFiles="$(NativeBuildOutputDirAbs)\$(OrtPackageId).$(PackageVersion).nupkg"
DestinationFolder="$(NativeBuildOutputDirAbs)\nuget-local-artifacts"
<Copy SourceFiles="$(NativeBuildOutputDirAbs)\$(OrtPackageId).$(PackageVersion).nupkg"
DestinationFolder="$(NativeBuildOutputDirAbs)\nuget-local-artifacts"
/>
</Target>

View file

@ -4,66 +4,53 @@
<OrtPackageId Condition="'$(OrtPackageId)' == ''">Microsoft.ML.OnnxRuntime</OrtPackageId>
</PropertyGroup>
<!--
Temporary setup until official Visual Studio 2022 release supports .net6, as the CIs require the official release.
We will be able to build all targets with VS once that happens.
Until then, we need to build the pre-.net6 targets with VS and the .net6 targets with dotnet.
The pre-.net6 Xamarin targets are optional and only included if the machine has the required workloads.
We have 3 scenarios
1) Build pre-net6 targets with VS - SelectedTargets=PreNet6
2) Build net6 targets - SelectedTargets=Net6
3) Run 'Pack' target to create nuget package from combination of 1 and 2 - SelectedTargets=All
Default is PreNet6 so that existing projects and CI builds will do the same thing unless explicitly updated.
-->
<PropertyGroup>
<SelectedTargets>PreNet6</SelectedTargets>
<BaseTargets>netstandard2.0;netcoreapp3.1;net6.0</BaseTargets>
<IncludeMobileTargets>true</IncludeMobileTargets>
<BaseTargets>netstandard2.0</BaseTargets>
<MobileTargets></MobileTargets>
</PropertyGroup>
<!-- only set the Xamarin mobile targets if we're building an ORT package,
and only if the mobile workloads are installed -->
<!-- special case the DesktopOnly solution -->
<PropertyGroup Condition="'$(SolutionName)' == 'OnnxRuntime.DesktopOnly.CSharp'">
<IncludeMobileTargets>false</IncludeMobileTargets>
</PropertyGroup>
<!-- add Xamarin mobile targets if we're building an ORT package and the Xamarin workloads are installed
NOTE: We include in a build of the managed package when creating Microsoft.ML.OnnxRuntime.Gpu as both
the CPU and GPU packaging pipelines can publish Microsoft.ML.OnnxRuntime.Managed, and we need the targets
to be consistent in both.
-->
<PropertyGroup Condition="('$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime' OR
'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Gpu') AND
Exists('$(MSBuildExtensionsPath)\Xamarin\Android') AND
Exists('$(MSBuildExtensionsPath)\Xamarin\iOS')">
<XamarinTargets>xamarinios10;monoandroid11.0</XamarinTargets>
'$(IncludeMobileTargets)' == 'true' AND
Exists('$(MSBuildExtensionsPath)\Xamarin\Android') AND
Exists('$(MSBuildExtensionsPath)\Xamarin\iOS')">
<MobileTargets>xamarinios10;monoandroid11.0</MobileTargets>
</PropertyGroup>
<PropertyGroup Condition="('$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Training') AND
Exists('$(MSBuildExtensionsPath)\Xamarin\Android')">
<XamarinTargetsForTraining>monoandroid11.0</XamarinTargetsForTraining>
<PropertyGroup Condition="'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Training' AND
'$(IncludeMobileTargets)' == 'true' AND
Exists('$(MSBuildExtensionsPath)\Xamarin\Android')">
<MobileTargets>monoandroid11.0</MobileTargets>
</PropertyGroup>
<!-- only set the .net6 targets if we're building an ORT package.
we can add .net6 support to other packages later as needed -->
<!-- add MAUI targets if building ORT package -->
<PropertyGroup Condition="('$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime' OR
'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Azure' OR
'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Gpu')">
<Net6Targets>net6.0;net6.0-android;net6.0-ios;net6.0-macos</Net6Targets>
'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Azure') AND
'$(IncludeMobileTargets)' == 'true'">
<MobileTargets>$(MobileTargets);net6.0-android;net6.0-ios</MobileTargets>
</PropertyGroup>
<PropertyGroup Condition="('$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Training')">
<Net6TargetsForTrainingPackage>net6.0;net6.0-android</Net6TargetsForTrainingPackage>
<PropertyGroup Condition="'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Training' AND
'$(IncludeMobileTargets)' == 'true'">
<MobileTargets>$(MobileTargets);net6.0-android</MobileTargets>
</PropertyGroup>
<PropertyGroup Condition="'$(SelectedTargets)'=='PreNet6'">
<TargetFrameworks>$(BaseTargets);$(XamarinTargets);$(XamarinTargetsForTraining)</TargetFrameworks>
<PropertyGroup>
<TargetFrameworks>$(BaseTargets);$(MobileTargets)</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(SelectedTargets)'=='Net6'">
<TargetFrameworks>$(Net6Targets);$(Net6TargetsForTrainingPackage)</TargetFrameworks>
</PropertyGroup>
<!-- nuget package creation -->
<PropertyGroup Condition="'$(SelectedTargets)'=='All'">
<TargetFrameworks>$(BaseTargets);$(XamarinTargets);$(XamarinTargetsForTraining);$(Net6Targets);$(Net6TargetsForTrainingPackage)</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<Platforms>AnyCPU;x86</Platforms>
<LangVersion>default</LangVersion>
@ -204,8 +191,9 @@
<DefineConstants>$(DefineConstants);$(OrtConstants)</DefineConstants>
</PropertyGroup>
<!-- debug output - makes finding/fixing any issues with the the conditions easy.
<!-- 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)'))' " />
@ -214,7 +202,6 @@
<Message Text="OrtConstants='$(OrtConstants)' " />
<Message Text="TargetFrameworks='$(TargetFrameworks)' " />
</Target>
-->
<ItemGroup>
<None Include="$(OnnxRuntimeCsharpRoot)\..\include\onnxruntime\core\session\onnxruntime_*.h"

View file

@ -0,0 +1,15 @@
<!-- csproj for use with `dotnet pack` on linux via build.py's `build_nuget` option.
Expected usage is to create a Microsoft.ML.OnnxRuntime native nuget package containing only the linux
libonnxruntime.so for local testing.
We only enable netstandard2.0 due to that, but additional frameworks can be added as needed.
If you need a more sophisticated package for testing, you can run the production packaging pipeline against your
branch and download the resulting nuget package from the build artifacts.
-->
<Project Sdk="MSBuild.Sdk.Extras/3.0.22">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<NuspecFile>$(OnnxRuntimeBuildDirectory)/NativeNuget.nuspec</NuspecFile>
</PropertyGroup>
</Project>

View file

@ -796,6 +796,7 @@ def run_subprocess(
my_env.update(env)
log.info(" ".join(args))
return run(*args, cwd=cwd, capture_stdout=capture_stdout, shell=shell, env=my_env)
@ -2024,13 +2025,6 @@ def build_python_wheel(
run_subprocess(args, cwd=cwd)
def derive_linux_build_property():
if is_windows():
return '/p:IsLinuxBuild="false"'
else:
return '/p:IsLinuxBuild="true"'
def build_nuget_package(
cmake_path,
source_dir,
@ -2043,7 +2037,6 @@ def build_nuget_package(
use_dnnl,
use_tvm,
use_winml,
use_snpe,
use_qnn,
enable_training_apis,
msbuild_extra_options,
@ -2054,83 +2047,93 @@ def build_nuget_package(
)
csharp_build_dir = os.path.join(source_dir, "csharp")
is_linux_build = derive_linux_build_property()
# in most cases we don't want/need to include the Xamarin mobile targets, as doing so means the Xamarin
# mobile workloads must be installed on the machine.
# they are only included in the Microsoft.ML.OnnxRuntime nuget package
sln = "OnnxRuntime.DesktopOnly.CSharp.sln"
have_exclude_mobile_targets_option = "IncludeMobileTargets=false" in msbuild_extra_options
# derive package name and execution provider based on the build args
target_name = "/t:CreatePackage"
execution_provider = '/p:ExecutionProvider="None"'
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime"'
enable_training_tests = '/p:TrainingEnabledNativeBuild="false"'
execution_provider = "/p:ExecutionProvider=None"
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime"
enable_training_tests = "/p:TrainingEnabledNativeBuild=false"
if enable_training_apis:
enable_training_tests = '/p:TrainingEnabledNativeBuild="true"'
enable_training_tests = "/p:TrainingEnabledNativeBuild=true"
if use_cuda:
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.Training.Gpu"'
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.Training.Gpu"
else:
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.Training"'
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.Training"
elif use_winml:
package_name = '/p:OrtPackageId="Microsoft.AI.MachineLearning"'
package_name = "/p:OrtPackageId=Microsoft.AI.MachineLearning"
target_name = "/t:CreateWindowsAIPackage"
elif use_openvino:
execution_provider = '/p:ExecutionProvider="openvino"'
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.OpenVino"'
execution_provider = "/p:ExecutionProvider=openvino"
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.OpenVino"
elif use_tensorrt:
execution_provider = '/p:ExecutionProvider="tensorrt"'
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.TensorRT"'
execution_provider = "/p:ExecutionProvider=tensorrt"
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.TensorRT"
elif use_dnnl:
execution_provider = '/p:ExecutionProvider="dnnl"'
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.DNNL"'
execution_provider = "/p:ExecutionProvider=dnnl"
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.DNNL"
elif use_cuda:
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu"'
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.Gpu"
elif use_rocm:
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.ROCm"'
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.ROCm"
elif use_tvm:
execution_provider = '/p:ExecutionProvider="tvm"'
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.Tvm"'
elif use_snpe:
execution_provider = '/p:ExecutionProvider="snpe"'
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.Snpe"'
execution_provider = "/p:ExecutionProvider=tvm"
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.Tvm"
elif use_qnn:
execution_provider = '/p:ExecutionProvider="qnn"'
package_name = '/p:OrtPackageId="Microsoft.ML.OnnxRuntime.QNN"'
execution_provider = "/p:ExecutionProvider=qnn"
package_name = "/p:OrtPackageId=Microsoft.ML.OnnxRuntime.QNN"
elif any(map(lambda x: "OrtPackageId=" in x, msbuild_extra_options)):
pass
else:
# use the solution file that includes Xamarin mobile targets
sln = "OnnxRuntime.CSharp.sln"
# we currently only allow building with mobile targets on Windows.
# it should be possible to allow building with android targets on Linux but that requires updating the
# csproj to separate the inclusion of ios and android targets.
if is_windows() and have_exclude_mobile_targets_option is False:
# use the sln that include the mobile targets
sln = "OnnxRuntime.CSharp.sln"
# explicitly exclude mobile targets in this case
if sln != "OnnxRuntime.CSharp.sln" and have_exclude_mobile_targets_option is False:
msbuild_extra_options.append("IncludeMobileTargets=false")
# expand extra_options to add prefix
extra_options = ["/p:" + option for option in msbuild_extra_options]
# we have to use msbuild directly if including Xamarin targets as dotnet only supports MAUI (.net6)
use_dotnet = sln != "OnnxRuntime.CSharp.sln"
if use_dotnet:
cmd_args = ["dotnet", "restore", sln, "--configfile", "NuGet.CSharp.config", *extra_options]
else:
cmd_args = ["msbuild", sln, "/t:restore", "/p:RestoreConfigFile=NuGet.CSharp.config", *extra_options]
# set build directory based on build_dir arg
native_dir = os.path.normpath(os.path.join(source_dir, build_dir))
ort_build_dir = '/p:OnnxRuntimeBuildDirectory="' + native_dir + '"'
ort_build_dir = "/p:OnnxRuntimeBuildDirectory=" + native_dir
# dotnet restore
cmd_args = ["dotnet", "restore", sln, "--configfile", "NuGet.CSharp.config"]
run_subprocess(cmd_args, cwd=csharp_build_dir)
# build csharp bindings and create nuget package for each config
for config in configs:
if is_linux():
native_build_dir = os.path.join(native_dir, config)
cmd_args = [cmake_path, "-DCMAKE_INSTALL_PREFIX=./nuget-staging/usr/local", "-Pcmake_install.cmake"]
run_subprocess(cmd_args, cwd=native_build_dir)
configuration = '/p:Configuration="' + config + '"'
configuration = "/p:Configuration=" + config
if not use_winml:
cmd_args = [
"dotnet",
cmd_args = ["dotnet"] if use_dotnet else []
cmd_args += [
"msbuild",
sln,
configuration,
package_name,
is_linux_build,
ort_build_dir,
enable_training_tests,
*extra_options,
]
run_subprocess(cmd_args, cwd=csharp_build_dir)
else:
winml_interop_dir = os.path.join(source_dir, "csharp", "src", "Microsoft.AI.MachineLearning.Interop")
@ -2141,7 +2144,7 @@ def build_nuget_package(
"msbuild",
winml_interop_project,
configuration,
'/p:Platform="Any CPU"',
"/p:Platform=Any CPU",
ort_build_dir,
"-restore",
]
@ -2155,26 +2158,28 @@ def build_nuget_package(
# this path is setup by cmake/nuget_helpers.cmake for MSVC on Windows
nuget_exe = os.path.normpath(os.path.join(native_dir, config, "nuget_exe", "src", "nuget.exe"))
else:
# user needs to make sure nuget is installed and can be found
nuget_exe = "nuget"
# `dotnet pack` is used on Linux
nuget_exe = "NugetExe_not_set"
nuget_exe_arg = '/p:NugetExe="' + nuget_exe + '"'
cmd_args = [
"dotnet",
cmd_args = ["dotnet"] if use_dotnet else []
cmd_args += [
"msbuild",
"OnnxRuntime.CSharp.proj",
target_name,
package_name,
configuration,
execution_provider,
is_linux_build,
ort_build_dir,
nuget_exe_arg,
*extra_options,
]
cmd_args.extend(msbuild_extra_options)
run_subprocess(cmd_args, cwd=csharp_build_dir)
log.info(f"nuget package was created in the {config} build output directory.")
def run_csharp_tests(source_dir, build_dir, use_cuda, use_openvino, use_tensorrt, use_dnnl, enable_training_apis):
# Currently only running tests on windows.
@ -2637,6 +2642,7 @@ def main():
enable_training_apis=args.enable_training_apis,
enable_rocm_profiling=args.enable_rocm_profiling,
)
if args.build_nuget:
build_nuget_package(
cmake_path,
@ -2650,7 +2656,6 @@ def main():
args.use_dnnl,
args.use_tvm,
args.use_winml,
args.use_snpe,
args.use_qnn,
args.enable_training_apis,
normalize_arg_list(args.msbuild_extra_options),

View file

@ -716,44 +716,29 @@ stages:
versionSpec: 6.2.1
- task: PowerShell@2
displayName: Install .NET 6 workloads
displayName: Install mobile workloads
inputs:
targetType: 'inline'
script: |
dotnet workload install android ios 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 }} -p:ReleaseVersionSuffix=$(ReleaseVersionSuffix)
dotnet workload install android ios
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
displayName: 'Restore NuGet Packages and create project.assets.json for pre-.net6 targets'
displayName: 'Restore NuGet Packages and create project.assets.json'
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"'
msbuildArguments: '-t:restore -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu"'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
displayName: 'Build C# for pre-.net6 targets'
displayName: 'Build C# bindings'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
configuration: RelWithDebInfo
platform: 'Any CPU'
msbuildArguments: '-p:SelectedTargets=PreNet6 -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu" -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }} -p:ReleaseVersionSuffix=$(ReleaseVersionSuffix)'
msbuildArguments: '-p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId="Microsoft.ML.OnnxRuntime.Gpu" -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }} -p:ReleaseVersionSuffix=$(ReleaseVersionSuffix)'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- template: templates/win-esrp-dll.yml
@ -762,15 +747,6 @@ stages:
DisplayName: 'ESRP - Sign C# dlls'
DoEsrp: ${{ parameters.DoEsrp }}
- task: MSBuild@1
displayName: Update projects.assets.json with 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:

View file

@ -137,7 +137,7 @@ stages:
- task: MSBuild@1
displayName: 'Restore NuGet Packages'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.DesktopOnly.CSharp.sln'
platform: 'Any CPU'
configuration: '$(BuildConfig)'
msbuildArguments: '-t:restore -p:OrtPackageId=${{ parameters.OrtPackageId }}'
@ -146,7 +146,7 @@ stages:
- task: MSBuild@1
displayName: 'Build C#'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.DesktopOnly.CSharp.sln'
configuration: '$(BuildConfig)'
platform: 'Any CPU'
msbuildArguments: '-p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=${{ parameters.OrtPackageId }} -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}'

View file

@ -398,44 +398,29 @@ stages:
versionSpec: 6.2.1
- task: PowerShell@2
displayName: Install .NET 6 workloads
displayName: Install mobile workloads
inputs:
targetType: 'inline'
script: |
dotnet workload install android ios 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 }} -p:ReleaseVersionSuffix=$(ReleaseVersionSuffix)
dotnet workload install android ios
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
displayName: 'Restore NuGet Packages and create project.assets.json for pre-.net6 targets'
displayName: 'Restore NuGet Packages and create project.assets.json'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
platform: 'Any CPU'
configuration: RelWithDebInfo
msbuildArguments: '-t:restore -p:SelectedTargets=PreNet6 -p:OrtPackageId=$(OrtPackageId)'
msbuildArguments: '-t:restore -p:OrtPackageId=$(OrtPackageId)'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
displayName: 'Build C# for pre-.net6 targets'
displayName: 'Build C# bindings'
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 }} -p:ReleaseVersionSuffix=$(ReleaseVersionSuffix)'
msbuildArguments: '-p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId) -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }} -p:ReleaseVersionSuffix=$(ReleaseVersionSuffix)'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- ${{ if eq(parameters.DoEsrp, true) }}:
@ -445,15 +430,6 @@ stages:
DisplayName: 'ESRP - Sign C# dlls'
DoEsrp: ${{ parameters.DoEsrp }}
- task: MSBuild@1
displayName: Update projects.assets.json with 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:

View file

@ -169,7 +169,7 @@ jobs:
- task: MSBuild@1
displayName: 'Restore NuGet Packages'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.DesktopOnly.CSharp.sln'
platform: 'Any CPU'
configuration: '${{ parameters.BuildConfig }}'
msbuildArguments: '-t:restore -p:OrtPackageId=$(OrtPackageId)'
@ -178,7 +178,7 @@ jobs:
- task: MSBuild@1
displayName: 'Build C#'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.DesktopOnly.CSharp.sln'
configuration: '${{ parameters.BuildConfig }}'
platform: 'Any CPU'
msbuildArguments: '-p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId)'
@ -197,7 +197,7 @@ jobs:
command: test
projects: '$(Build.SourcesDirectory)\csharp\test\Microsoft.ML.OnnxRuntime.Tests.NetCoreApp\Microsoft.ML.OnnxRuntime.Tests.NetCoreApp.csproj'
configuration: '${{ parameters.BuildConfig }}'
arguments: '--configuration ${{ parameters.BuildConfig }} -p:Platform="Any CPU" -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId) --blame'
arguments: '--configuration ${{ parameters.BuildConfig }} -p:Platform="Any CPU" -p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId) -p:IncludeMobileTargets=false --blame'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- ${{ if eq(parameters.EnablePython, true) }}:

View file

@ -222,44 +222,29 @@ stages:
versionSpec: 6.2.1
- task: PowerShell@2
displayName: Install .NET 6 workloads
displayName: Install mobile workloads
inputs:
targetType: 'inline'
script: |
dotnet workload install android
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 }} -p:ReleaseVersionSuffix=$(ReleaseVersionSuffix)
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
displayName: 'Restore NuGet Packages and create project.assets.json for pre-.net6 targets'
displayName: 'Restore NuGet Packages and create project.assets.json'
inputs:
solution: '$(Build.SourcesDirectory)\csharp\OnnxRuntime.CSharp.sln'
platform: 'Any CPU'
configuration: RelWithDebInfo
msbuildArguments: '-t:restore -p:SelectedTargets=PreNet6 -p:OrtPackageId=$(OrtPackageId)'
msbuildArguments: '-t:restore -p:OrtPackageId=$(OrtPackageId)'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: MSBuild@1
displayName: 'Build C# for pre-.net6 targets'
displayName: 'Build C# bindings'
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 }}'
msbuildArguments: '-p:OnnxRuntimeBuildDirectory="$(Build.BinariesDirectory)" -p:OrtPackageId=$(OrtPackageId) -p:IsReleaseBuild=${{ parameters.IsReleaseBuild }}'
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- ${{ if eq(parameters.DoEsrp, true) }}:
@ -269,15 +254,6 @@ stages:
DisplayName: 'ESRP - Sign C# dlls'
DoEsrp: ${{ parameters.DoEsrp }}
- task: MSBuild@1
displayName: Update projects.assets.json with 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:

View file

@ -557,7 +557,7 @@ def generate_files(line_list, args):
files_list.append(
"<file src="
+ '"'
+ os.path.join(args.native_build_path, "nuget-staging/usr/local/lib", "libonnxruntime.so")
+ os.path.join(args.native_build_path, "libonnxruntime.so")
+ '" target="runtimes\\linux-'
+ args.target_architecture
+ '\\native" />'
@ -793,8 +793,10 @@ def generate_files(line_list, args):
"<file src=" + '"' + os.path.join(args.native_build_path, nuget_dependencies["tvm"]) + runtimes + " />"
)
# Some tools to be packaged in nightly build only, should not be released
# Some tools to be packaged in nightly debug build only, should not be released
# These are copied to the runtimes folder for convenience of loading with the dlls
# NOTE: nuget gives a spurious error on linux if these aren't in a separate directory to the library so
# we add them to a tools folder for that reason.
if (
args.is_release_build.lower() != "true"
and args.target_architecture == "x64"
@ -804,7 +806,10 @@ def generate_files(line_list, args):
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["onnxruntime_perf_test"])
+ runtimes
+ runtimes[:-1]
+ "\\tools\\"
+ nuget_dependencies["onnxruntime_perf_test"]
+ '"'
+ " />"
)
@ -817,7 +822,10 @@ def generate_files(line_list, args):
"<file src="
+ '"'
+ os.path.join(args.native_build_path, nuget_dependencies["onnx_test_runner"])
+ runtimes
+ runtimes[:-1]
+ "\\tools\\"
+ nuget_dependencies["onnx_test_runner"]
+ '"'
+ " />"
)
@ -871,7 +879,6 @@ def generate_files(line_list, args):
os.system(copy_command + " " + source_props + " " + target_props)
files_list.append("<file src=" + '"' + target_props + '" target="build\\native" />')
if not is_snpe_package and not is_qnn_package:
files_list.append("<file src=" + '"' + target_props + '" target="build\\netstandard1.1" />')
files_list.append("<file src=" + '"' + target_props + '" target="build\\netstandard2.0" />')
# Process targets file
@ -890,7 +897,6 @@ def generate_files(line_list, args):
os.system(copy_command + " " + source_targets + " " + target_targets)
files_list.append("<file src=" + '"' + target_targets + '" target="build\\native" />')
if not is_snpe_package and not is_qnn_package:
files_list.append("<file src=" + '"' + target_targets + '" target="build\\netstandard1.1" />')
files_list.append("<file src=" + '"' + target_targets + '" target="build\\netstandard2.0" />')
# Process xamarin targets files