简体   繁体   中英

.Net Framework 4.7.2 Referencing .Net Standard 2.0 project

My situation: I have a.Net 4.7.2 WinForms application. It references a project that is a.Net Standard class library The.Net Standard library references the Microsoft.SqlServer.SqlManagementObjects NuGet package using a PackageReference

When I build the winforms application, it is pulling in the Microsoft.SqlServer.SqlManagementObjects package from the net462 lib folder instead of the netstandard2.0 folder. This is a problem because the.Net Standard version of the library has different classes (eg it uses Microsoft.Data.SqlConnection instead of System.Data.SqlConnection). So when the application is run you get an error saying System.MissingMethodException: Method not found: 'Void Microsoft.SqlServer.Management.Common.ServerConnection..ctor(Microsoft.Data.SqlClient.SqlConnection)'

Is there any way around this? I feel like the SMO libraries should have been separated into different packages for.Net Standard and.Net Framework if they have differences like this.

I believe the official position is that this is library authoring issue, so there isn't a good way to do what you want.

There is a heinous hack detailed here though, which is something like:

<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" ExcludeAssets="Compile" GeneratePathProperty="true">
    <Version>1.2.3</Version> 
</PackageReference>
<Reference Include="Microsoft.SqlServer.SqlManagementObjects">
    <HintPath>$(PkgMicrosoft_SqlServer_SqlManagementObjects)lib\netstandard2.0\Microsoft.SqlServer.SqlManagementObjects.dll</HintPath> 
</Reference>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM