Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Transitive dependency(PackageReference/ProjectReference)not working when app and libs has different targetFramework #1149

Closed
yyjdelete opened this issue Apr 17, 2019 · 1 comment

Comments

@yyjdelete
Copy link

Also report as dotnet/sdk#3103, dotnet/core#2571.

Reference transitive not working when app and lib has different targetFramework, and the lib use an transitive dependency from special targetFramework of an multi-targetFramework PackageReference/ProjectReference

That mainly affect reference any libraries which target single netstandard2.0 and reference other multi-targetFramework libraries , as it give no warn/error at build time.

Step:

Tested with dotnet-sdk : 3.0.100-preview3-010431, 2.1.504 and some other version

Run ConsoleApp5 in https://github.com/yyjdelete/test_dotnet_indirect_dependency
And see an FileNotFoundException for System.Data.SqlClient, Version=4.5.0.0(Ignore the MissingMethodException, as it's expected #1052 (comment)). The same if replace ClassLibrary1 and ClassLibrary2 with packed .nupkg

Project struct:

ConsoleApp5(net472)
|--ClassLibrary1(netstandard2.0)->use `System.Data.SqlClient` directly or exported as public api of `ClassLibrary2`
---|--ClassLibrary2(netstandard2.0;net472)
------|--System.Data.SqlClient(when netstandard2.0)

Expected:

ConsoleApp5(net472)
|--ClassLibrary1(netstandard2.0)
---|--System.Data.SqlClient(net472)
---|--ClassLibrary2(net472)
  1. The System.Data.SqlClient should be include in the output bins of ConsoleApp5, if used by ClassLibrary1(netstandard2.0).
    Or at least give an warning, to make people know which Reference must be added explicitly. It's almost impossibe to find all of them by hand in an project with deep reference transitive(can also be something in nupkg).

  2. VisualStudio should show the same result of project struct as the output does, and System.Data.SqlClient should be include again with ClassLibrary1(netstandard2.0) if it's removed with ClassLibrary2(net472)
    I already know it's reasonable to reference ClassLibrary2 with net472(runtime) instead of netstandard2.0, so ignore the MissingMethodException.

Actual:

ConsoleApp5(net472)
|--ClassLibrary1(netstandard2.0)
---|--ClassLibrary2(net472)

***System.Data.SqlClient is missing
  1. The System.Data.SqlClient is missing from the output, even it's used by ClassLibrary1(netstandard2.0), and get an FileNotFoundException when execute.
  2. VisualStudio show that ConsoleApp5(net472) use ClassLibrary2(net472), while the output use ClassLibrary2(netstandard2.0).
    image
@wtgodbe wtgodbe added this to the .NET Standard vNext milestone Jun 21, 2019
@wtgodbe wtgodbe added the question General question, not a problem in source code or documentation (yet) label Jun 21, 2019
@terrajobst terrajobst added bug and removed question General question, not a problem in source code or documentation (yet) labels Aug 19, 2022
@terrajobst
Copy link
Member

We decided to close this issue as won't fix.

The issue here is likely that the console application is in packages.config-mode (the default) while .NET Standard uses PackageReference (the only mode). The solution is to mark the .NET Framework project to use PackageReference:

<PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

See Using PackageReference for a project with no package dependencies for more details.

@terrajobst terrajobst closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants