dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.72k stars 1.07k forks source link

aspnetcorev2_inprocess should not be published for PublishAot libraries #40487

Open eerhardt opened 6 months ago

eerhardt commented 6 months ago

Describe the bug

When building a Native AOT library that references an ASP.NET nuget package on windows, the aspnetcorev2_inprocess.dll is being published to the output folder.

To Reproduce

dotnet publish -r win-x64 the following library:

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <InvariantGlobalization>true</InvariantGlobalization>
    <PublishAot>true</PublishAot>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
  </ItemGroup>
</Project>
using Microsoft.AspNetCore.Authentication.JwtBearer;
using System.Runtime.InteropServices;

namespace MyLibrary;

public static class EntryPoints
{
    [UnmanagedCallersOnly(EntryPoint = "MyValidate")]
    public static int MyValidate()
    {
        JwtBearerPostConfigureOptions o = new JwtBearerPostConfigureOptions();
        return 1;
    }
}

Look in the bin\Release\net8.0\win-x64\publish folder:

image

that aspnetcorev2_inprocess.dll shouldn't be present. It is not used by the library.

This is similar to https://github.com/dotnet/sdk/issues/29896, but for libraries and not web apps.

Exceptions (if any)

N/A

Further technical details

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.300-preview.24203.14\

.NET workloads installed: [aspire] Installation Source: SDK 8.0.300-preview.24203, VS 17.11.34822.286 Manifest Version: 8.0.0-preview.7.24224.7/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.0-preview.7.24224.7\WorkloadManifest.json Install Type: FileBased

Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2

.NET SDKs installed: 3.1.426 [C:\Program Files\dotnet\sdk] 6.0.129 [C:\Program Files\dotnet\sdk] 6.0.321 [C:\Program Files\dotnet\sdk] 6.0.421 [C:\Program Files\dotnet\sdk] 7.0.118 [C:\Program Files\dotnet\sdk] 7.0.408 [C:\Program Files\dotnet\sdk] 8.0.300-preview.24203.14 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download



cc @halter73 @DamianEdwards 
DamianEdwards commented 6 months ago

Huh that's interesting. What is it that triggers the copying of that file, the transitive <FrameworkReference />?

eerhardt commented 6 months ago

What is it that triggers the copying of that file, the transitive ?

Correct. It originates from resolving the "RuntimePack" assets:

image

In https://github.com/dotnet/sdk/pull/29984/, we ended up setting PublishIISAssets=false when PublishAot == true. But that is only with the WebSDK, which doesn't really help here since I'm just building a library and the ASP.NET runtime pack is getting brought in transitively.