Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing with win-x64 RID doesn't include runtime-specific Nuget libraries #10665

Closed
nxtn opened this issue Feb 18, 2020 · 4 comments
Closed

Comments

@nxtn
Copy link
Contributor

nxtn commented Feb 18, 2020

Steps to reproduce

Reference a Nuget package with runtime-specific libraries.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Management.Infrastructure" Version="2.0.0" />
  </ItemGroup>

</Project>
  • dotnet publish
\publish
  \runtimes
    \win7-x64
      \lib\netstandard1.6\Microsoft.Management.Infrastructure.dll
      ...
    \win7-x86
      \lib\netstandard1.6\Microsoft.Management.Infrastructure.dll
      ...
    \win10-x64
      \lib\netstandard1.6\Microsoft.Management.Infrastructure.dll
      ...
    \win10-x86
      \lib\netstandard1.6\Microsoft.Management.Infrastructure.dll
      ...
    ...
  ...
  • dotnet publish -r win10-x64
\publish
  \Microsoft.Management.Infrastructure.dll
  ...
  • dotnet publish -r win-x64

No library from the Nuget package is copied to /publish directory.

Expected behavior

  • dotnet publish -r win-x64
\publish
  \runtimes
    \win7-x64
      \lib\netstandard1.6\Microsoft.Management.Infrastructure.dll
      ...
    \win10-x64
      \lib\netstandard1.6\Microsoft.Management.Infrastructure.dll
      ...
    ...
  ...

Actual behavior

dotnet publish -r win-x64 succeeds, but the produced program will definitely crash.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

Environment data

.NET Core SDK (reflecting any global.json):
 Version:   3.1.200-preview-014883
 Commit:    4e2a0ee959

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.200-preview-014883\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  3.1.200-preview-014883 [C:\Program Files\dotnet\sdk]
@davedx
Copy link

davedx commented Feb 26, 2020

I think we have the same issue with SqlClient dll's and dotnet publish. I actually made an issue on their repo but it probably should be here too.
dotnet/SqlClient#445

I made a reproduction repo for the issue here: https://github.com/davedx/sqlclient-repro

Edit: I narrowed this down some.

If you have do dotnet build first without specifying --runtime, then do dotnet publish with --runtime, it doesn't work. But if you specify --runtime when you do the dotnet build then it works correctly.

This behaviour is new for us

Another edit: I downgraded my repro project to dotnet 2.1 and the behaviour above does not happen. It appears this is because the build command in 2.1 did not do a "restore" automatically? So maybe this isn't a bug but a very subtle breaking change...

Final edit: here it is, the breaking change, documented: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#build-copies-dependencies

Seems like a nice quality of life improvement, but for platform specific builds it can cause a lot of pain...

@richlander
Copy link
Member

I just tried to repro this with the .NET 6 SDK. This is what I see. Does that resolve the issue?

root@a1e6b08d8845:/app# dotnet publish -r win10-x64
root@a1e6b08d8845:/app# find bin/Debug/net6.0/win10-x64/publish/ | grep Microsoft.Man
bin/Debug/net6.0/win10-x64/publish/Microsoft.Management.Infrastructure.Native.dll
bin/Debug/net6.0/win10-x64/publish/Microsoft.Management.Infrastructure.dll
bin/Debug/net6.0/win10-x64/publish/Microsoft.Management.Infrastructure.Native.Unmanaged.dll
root@a1e6b08d8845:/app# 

@PatrickKunz
Copy link

PatrickKunz commented Oct 13, 2023

I publish with the following command on my Apple arm computer with dotNet arm installed:

dotnet publish -c Release --runtime win-x64 --no-self-contained

I wasn't able to make it work on a Windows x64 system. There is no runtime folder in the publish folder.

@nxtn
Copy link
Contributor Author

nxtn commented Jun 5, 2024

It is recommended to use portable RIDs, such as win-x64, instead of version-specific RIDs, such as win10-x64, since .NET 8.

For more information, see Using RIDs and .NET SDK uses a smaller RID graph.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
  </ItemGroup>

</Project>
  • dotnet publish
\publish
  \runtimes
    \win-x64
      \lib\netstandard1.6\microsoft.management.infrastructure.dll
      ...
    \win-x86
      \lib\netstandard1.6\microsoft.management.infrastructure.dll
      ...
    ...
  ...
  • dotnet publish -r win-x64
\publish
  \Microsoft.Management.Infrastructure.dll
  ...
  • dotnet publish -r win10-x64 -p:UseRidGraph=true
\publish
  \Microsoft.Management.Infrastructure.dll
  ...

@nxtn nxtn closed this as completed Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants