-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Reference transitive not working well when app and libs has different targetFramework, and lib use an transitive reference from special targetFramework of an multi-targetFramework PackageReference/ProjectReference #3103
Comments
You seem to expose a different public API from ClassLibrary2 when compiled for different target frameworks. This will cause MissingMethodExceptions due to every project selecting the "nearest" target framework for project and package references. Especially exposing different public APIs between a .NET Standard and .NET Framework build is dangerous since .NET Standard is compatible with .NET Framework and you may end up in such a situation with intermediate .NET Standard projects/packages. It is less of a problem when exposing different API surfaces between .NET Core and .NET Framework TFMs (but may still exist due to the .NET Framework compatibility when you target e.g. |
The MissingMethodException is just a part of test-case here and not the main issue in my code. The main issue I hit is that Reference the below project from an App with <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="1.60.6" />
</ItemGroup>
</Project>
using System;
using System.Data.SqlClient;
namespace ClassLibrary1
{
public class Class2
{
public void Test()
{
using (var x = new SqlConnection())
{
}
}
}
} And the expected behavior in #3103 (comment) is the current behavior of project struct of VS2019, if it's not expected, it's another issue. |
Try to add an
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D961573D-C904-4B7E-996E-48C0F37598B6}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApp2</RootNamespace>
<AssemblyName>ConsoleApp2</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj">
<Project>{d16e7a90-74ac-487f-8db6-9ffb45841f98}</Project>
<Name>ClassLibrary1</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> |
may this microsoft/dotnet#860 be related? |
….8 (#3103) - Microsoft.DotNet.Cli.Runtime - 5.0.100-alpha1.19505.8
Sdk Version:
3.0.100-preview3-010431
,2.1.504
Run
ConsoleApp5
in https://github.com/yyjdelete/test_dotnet_indirect_dependencyAnd see an
MissingMethodException
and anFileNotFoundException
forSystem.Data.SqlClient, Version=4.5.0.0
This can also happen with
PackageReference
. I reference Dapper from an ClassLibrary with netstandard2.0, and the main App is net472, and failed to foundSystem.Data.SqlClient, Version=4.5.0.0
.Project struct:
Expected:
The
FileNotFoundException
not happen and theSystem.Data.SqlClient, Version=4.5.0.0
is include in the output bins.The below behavior may be not expected, but it's the current behavior for project struct(dependencies) in VS2019. (Rider follow the actual behavior for project struct)
Actual:
The text was updated successfully, but these errors were encountered: