Skip to content

Native assemblies from NuGet aren't copied correctly for packages.config #1851

@eerhardt

Description

@eerhardt

System information

  • OS version/distro: Windows
  • .NET Version (eg., dotnet --info): .NET Framework 4.7.1

Issue

  • What did you do?
    Create an "old style" .csproj using packages.config and added Microsoft.ML nuget package and built.

When creating the project, if you uncheck the "Create directory for solution" checkbox, then the .sln and .csproj are in the same folder. When you restore NuGet packages, the nuget files get put in a packages folder in the same folder as the .csproj.

  • What happened?
    The native assemblies (CpuMathNative, FastTreeNative, LdaNative, etc) were all copied into subdirectories of my output path instead of directly in my output path.

From looking at a binlog of the build, it appears that the AssignTargetPath is getting confused at our Content items since they appear to be part of the project (since they are under the same folder as the .csproj).

  • What did you expect?
    The native assemblies should be copied directly to the output folder.

Note

To fix this, we should put the <Link> metadata on our content items:

<Content Include="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x64\native\*.dll"
Condition="'$(PlatformTarget)' == 'x64'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x86\native\*.dll"
Condition="'$(PlatformTarget)' == 'x86'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
</ItemGroup>

See

For other places that had this same bug.

Metadata

Metadata

Assignees

Labels

BuildBuild related issuebugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions