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.71k stars 1.06k forks source link

Creating a plugin project will copy dependencies of your plugin base to the plugins output #31636

Open tisis2 opened 1 year ago

tisis2 commented 1 year ago

Describe the bug

i created a plugin like is described in https://learn.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support this will still cause dependencies of your PluginBase to be copied to the output of your Plugin project. in the Plugin project <Private>false</Private> is added to avoid the dll of PluginBase being copied but its dependencies will still be copied.

i created a small sample to illustrate that issue: PluginSample.zip here is the tree that gets built:

SolutionDirectory
|   PluginSample.sln
|
+---Plugin
|   |   ...
|   +---bin
|   |   \---Debug
|   |       \---net6.0
|   |               Plugin.deps.json
|   |               Plugin.dll
|   |               Plugin.pdb
|   |               PluginBaseDependency.dll <-------- Should not be here
|   |               PluginBaseDependency.pdb <-------- Should not be here
|   |               PluginDependency.dll
|   |               PluginDependency.pdb
|   \---obj
|       ...
|
+---PluginBase
|   |   ...
|   +---bin
|   |   \---Debug
|   |       \---net6.0
|   |               PluginBase.deps.json
|   |               PluginBase.dll
|   |               PluginBase.pdb
|   |               PluginBaseDependency.dll
|   |               PluginBaseDependency.pdb
|   \---obj
|       ...
|
+---PluginBaseDependency
|   |   ...
|   +---bin
|   |   \---Debug
|   |       \---net6.0
|   |               PluginBaseDependency.deps.json
|   |               PluginBaseDependency.dll
|   |               PluginBaseDependency.pdb
|   \---obj
|       ...
|
+---PluginDependency
|   |   ...
|   +---bin
|   |   \---Debug
|   |       \---net6.0
|   |               PluginDependency.deps.json
|   |               PluginDependency.dll
|   |               PluginDependency.pdb
|   \---obj
|       ...
|
\---PluginSampleApp
    |   ...
    +---bin
    |   \---Debug
    |       \---net6.0
    |           |   PluginBase.dll
    |           |   PluginBase.pdb
    |           |   PluginBaseDependency.dll
    |           |   PluginBaseDependency.pdb
    |           |   PluginSampleApp.deps.json
    |           |   PluginSampleApp.dll
    |           |   PluginSampleApp.exe
    |           |   PluginSampleApp.pdb
    |           |   PluginSampleApp.runtimeconfig.json
    |           \---plugins
    \---obj
        ...

since the dependencies of the PluginBase is already part of your application, they should not be copied to the output of your plugin. they should be used from your application like it is with the PluginBase itself

To Reproduce

Further technical details

Laufzeitumgebung: OS Name: Windows OS Version: 10.0.19045 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.202\

Host: Version: 7.0.4 Architecture: x64 Commit: 0a396acafe

.NET SDKs installed: 6.0.401 [C:\Program Files\dotnet\sdk] 6.0.402 [C:\Program Files\dotnet\sdk] 6.0.407 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk] 7.0.202 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.4 [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


- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
  - VS2022(17.5.3) and Rider but it should not matter actually
dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

KalleOlaviNiemitalo commented 1 year ago

Same result with <IncludeAssets>compile</IncludeAssets>, using .NET SDK 8.0.100-preview.1.23115.2.

https://github.com/dotnet/msbuild/issues/4371#issuecomment-1195950719 suggests setting <DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences>. That does not work here as is, because Plugin uses a type defined in PluginBaseDependency and so needs some kind of reference to it. If you add a direct reference to PluginBaseDependency as well, then it's OK:

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

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences>
    </PropertyGroup>

    <ItemGroup>
        <ProjectReference Include="..\PluginBase\PluginBase.csproj">
            <Private>false</Private>
            <ExcludeAssets>runtime</ExcludeAssets>
        </ProjectReference>

        <ProjectReference Include="..\PluginBaseDependency\PluginBaseDependency.csproj">
            <Private>false</Private>
            <ExcludeAssets>runtime</ExcludeAssets>
        </ProjectReference>

        <ProjectReference Include="..\PluginDependency\PluginDependency.csproj" />
    </ItemGroup>

</Project>

I do feel there should be a better way to control this, though.

KalleOlaviNiemitalo commented 1 year ago

Also related https://github.com/dotnet/msbuild/pull/8494 and https://github.com/dotnet/msbuild/issues/8507.

marcpopMSFT commented 1 year ago

@nkolev92 @JonDouglas Is there a way to disable transitive package reference copy in this case? Is this a feature update needed in NuGet?

nkolev92 commented 1 year ago

There's no knobs for controlling transitivity in any way right now.

IE, you can't specify includeassets/excludeassets for transitive packages or anything like that.

I think I've seen related issues, but I was unable to find it.

marcpopMSFT commented 1 year ago

Thanks. Sounds like there's no built in way to do this today. Moving to the backlog to gather additional feedback for consideration in the future.

Kkamikadzee commented 5 months ago

I encountered a similar problem, the issue is in the backlog and you can’t expect a solution? Can anyone share workarounds to solve the problem?