You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use the (native) Microsoft.ML.OnnxRuntime package in a C++ project via PackageReference. However, the package's nuspec does not include a dependency group for a native TFM. Nuget interprets this as meaning the package does not support native consumers. This results in the package being restored using a fallback target framework, along with a (transitive, undesirable) dependency on the managed package and a NU1701 warning.
The package's nuspec should include an empty dependency group for the native target framework. This tells nuget that it's valid to install the package into native projects, and that the dependency on the managed package is not required for such projects.
This allows it to be restored in a native project without using a fallback TFM.
Some additional context, as to why I have this problem: I have a large repo with a mixture of C#, C++, and C++CLI projects. To facilitate interoperating the vcxproj and csproj projects, we've configured the vcxproj projects to restore using PackageReference and set up a global AssetTargetFallback:
(It seems that these props are needed in order to fully reproduce the issue - see below.) I acknowledge that this is hacky!
To reproduce
Create a default vcxproj project in visual studio. Add the config I mentioned above (the two sections labelled "PackageReference configuration" below) and add a PackageReference to Microsoft.ML.OnnxRuntime. I trimmed some stuff for my example:
Restore this project using msbuild /t:restore (from a developer command prompt) and observe the NU1701 warnings for the managed dependencies:
D:\test\Project1> msbuild /t:restore .\Project1.vcxproj
MSBuild version 17.13.19+0d9f5a35a for .NET Framework
Build started 21/03/2025 11:03:41.
Project "D:\test\Project1\Project1.vcxproj" on node 1 (Restore target(s)).
_GetAllRestoreProjectPathItems:
Determining projects to restore...
Restore:
X.509 certificate chain validation will use the default trust store selected by .NET for code signing.
X.509 certificate chain validation will use the default trust store selected by .NET for timestamping.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'Microsoft.ML.OnnxRuntime.Managed 1.21.0' was restored usin
g 'native,Version=v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version=v
0.0'. This package may not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Buffers 4.5.1' was restored using 'native,Version=v
0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version=v0.0'. This package
may not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Memory 4.5.5' was restored using 'native,Version=v0
.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version=v0.0'. This package m
ay not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Numerics.Vectors 4.5.0' was restored using 'native,
Version=v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version=v0.0'. This
package may not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Runtime.CompilerServices.Unsafe 4.5.3' was restored
using 'native,Version=v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Vers
ion=v0.0'. This package may not be fully compatible with your project.
Assets file has not changed. Skipping assets file writing. Path: D:\test\Project1\obj\project.assets.json
Restored D:\test\Project1\Project1.vcxproj (in 160 ms).
NuGet Config files used:
C:\Users\behodgson\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
All projects are up-to-date for restore.
Done Building Project "D:\test\Project1\Project1.vcxproj" (Restore target(s)).
Deferred Messages
Detailed Build Summary
======================
============================== Build Hierarchy (IDs represent configurations) =======================================
==============
Id : Exclusive Time Total Time Path (Targets)
---------------------------------------------------------------------------------------------------------------------
--------------
0 : 0.647s 0.859s D:\test\Project1\Project1.vcxproj (Restore)
| 1 : 0.027s 0.027s D:\test\Project1\Project1.vcxproj (_IsProjectRestoreSupported)
| 2 : 0.002s 0.002s D:\test\Project1\Project1.vcxproj (_GenerateRestoreProjectPathWal
k)
| 3 : 0.113s 0.113s D:\test\Project1\Project1.vcxproj (_GenerateRestoreGraphProjectEn
try)
. 4 : 0.070s 0.070s D:\test\Project1\Project1.vcxproj (_GenerateProjectRestoreGraph)
============================== Node Utilization (IDs represent configurations) ======================================
==============
Timestamp: 1 Duration Cumulative
---------------------------------------------------------------------------------------------------------------------
--------------
638781662216290522: 0 0.165s 0.165s ...
638781662217940984: 1 0.027s 0.193s
638781662218215952: 0 0.017s 0.210s
638781662218385954: 2 0.002s 0.212s
638781662218405954: 0 0.002s 0.214s
638781662218425956: 3 0.113s 0.326s ..
638781662219551060: 0 0.001s 0.327s
638781662219561077: 4 0.070s 0.397s .
638781662220261289: 0 0.462s 0.859s .........
---------------------------------------------------------------------------------------------------------------------
--------------
Utilization: 100.0 Average Utilization: 100.0
Build succeeded.
"D:\test\Project1\Project1.vcxproj" (Restore target) (1) ->
(Restore target) ->
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'Microsoft.ML.OnnxRuntime.Managed 1.21.0' was restored us
ing 'native,Version=v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version
=v0.0'. This package may not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Buffers 4.5.1' was restored using 'native,Version
=v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version=v0.0'. This packag
e may not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Memory 4.5.5' was restored using 'native,Version=
v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version=v0.0'. This package
may not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Numerics.Vectors 4.5.0' was restored using 'nativ
e,Version=v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Version=v0.0'. Th
is package may not be fully compatible with your project.
D:\test\Project1\Project1.vcxproj : warning NU1701: Package 'System.Runtime.CompilerServices.Unsafe 4.5.3' was restor
ed using 'native,Version=v0.0, .NETFramework,Version=v4.7.2, net8.0' instead of the project target framework 'native,Ve
rsion=v0.0'. This package may not be fully compatible with your project.
5 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.87
You can also find the undesirable managed dependencies in the generated assets file:
If I edit the nuspec file in my machine-level package cache, to add the empty dependency group as detailed above, the issue is resolved.
Urgency
Not urgent as it's just a build warning, but probably an easy fix 😉
Platform
Windows
OS Version
11
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.21.0
ONNX Runtime API
C++
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response
The text was updated successfully, but these errors were encountered:
benjamin-hodgson
changed the title
Microsoft.ML.OnnxRuntime package should have a 'native' dependency group
Microsoft.ML.OnnxRuntime Nuget package should have a 'native' dependency group
Mar 21, 2025
Describe the issue
I would like to use the (native)
Microsoft.ML.OnnxRuntime
package in a C++ project viaPackageReference
. However, the package's nuspec does not include a dependency group for anative
TFM. Nuget interprets this as meaning the package does not support native consumers. This results in the package being restored using a fallback target framework, along with a (transitive, undesirable) dependency on the managed package and a NU1701 warning.The package's nuspec should include an empty dependency group for the
native
target framework. This tells nuget that it's valid to install the package into native projects, and that the dependency on the managed package is not required for such projects.This allows it to be restored in a native project without using a fallback TFM.
Some additional context, as to why I have this problem: I have a large repo with a mixture of C#, C++, and C++CLI projects. To facilitate interoperating the vcxproj and csproj projects, we've configured the vcxproj projects to restore using PackageReference and set up a global AssetTargetFallback:
(It seems that these props are needed in order to fully reproduce the issue - see below.) I acknowledge that this is hacky!
To reproduce
Create a default vcxproj project in visual studio. Add the config I mentioned above (the two sections labelled "PackageReference configuration" below) and add a PackageReference to
Microsoft.ML.OnnxRuntime
. I trimmed some stuff for my example:Restore this project using
msbuild /t:restore
(from a developer command prompt) and observe the NU1701 warnings for the managed dependencies:You can also find the undesirable managed dependencies in the generated assets file:
If I edit the nuspec file in my machine-level package cache, to add the empty dependency group as detailed above, the issue is resolved.
Urgency
Not urgent as it's just a build warning, but probably an easy fix 😉
Platform
Windows
OS Version
11
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.21.0
ONNX Runtime API
C++
Architecture
X64
Execution Provider
Default CPU
Execution Provider Library Version
No response
The text was updated successfully, but these errors were encountered: