runtime icon indicating copy to clipboard operation
runtime copied to clipboard

.NET Core Solution design having issues with reference to old version libraries

Open avikenjale opened this issue 9 years ago • 10 comments

I am in process of designing a basic application, where I would need to utilize my exiting .net libraries which I have written using Framework 4.5

I am trying to design following structure:

-CODE
 - doamin.csproj  built on .NET 45 framework.(Portable Library Class)
  -Business.csproj
     - TargetFramework - netstandard1.1          
     - ProjectReference - domain.csproj 
  - WebApi.csproj
     -TargetFramework - netcoreapp1.1    
     - ProjectReference - Business.csproj 
-TEST
  - Business.Tests.csproj
     - TargetFramework - netstandard1.1          
     - ProjectReference - domain.csproj 
     - ProjectReference - Business.csproj 
  - WebAPI.Tests.csproj
     -TargetFramework - netcoreapp1.1    
     - ProjectReference - Business.csproj 
     - ProjectReference - WebApi.csproj 

Understanding:

  1. Business.csproj is targeting framework netstandard1.4, as both .NET Framework (4.5.x) & .NET Core implements netstandard1.4
  2. WebApi.csproj is targeting framework netcoreapp1.1 as it is need for ASP.NET Core features & referencing project Business.csproj built on netstandard1.4

Now when try to restore packages - I am getting following errors:

One or more packages are incompatible with .NETCoreApp,Version=v1.1.

Package Microsoft.Composition 1.0.27 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.Composition 1.0.27 supports: portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259) Error One or more packages are incompatible with .NETCoreApp,Version=v1.1.

avikenjale avatar May 26 '17 14:05 avikenjale

@weshaggard

danmoseley avatar May 26 '17 15:05 danmoseley

cc @ericstj

karelz avatar May 26 '17 16:05 karelz

as both .NET Framework (4.5.x) & .NET Core implements netstandard1.6

That's incorrect. net45 only supports netstandard1.1. See https://docs.microsoft.com/en-us/dotnet/standard/library.

That's not the cause of this issue though.

Microsoft.Composition doesn't support any version of netstandard, nor netcoreapp. Instead you should use the latest System.Composition. This issue is a duplicate of dotnet/runtime#21132.

ericstj avatar May 26 '17 19:05 ericstj

@ericstj , modified design little bit to support correct frameworks.

Question: Can PCL be referred in .NET core Libraries/projects? also can these be hosted in non-windows environment?

avikenjale avatar Jun 19 '17 13:06 avikenjale

/cc @terrajobst @weshaggard @AlexGhiondea

This might be more information than you want, but trying to give you a complete answer.

Profile-based PCLs didn't work in .NETCoreApp1.x seamlessly. NuGet would not let you use them but you could try to use them by specifying imports/PackageTargetFallBack.

If the PCL happened to only use .NET API (no windows PInvokes) and was System.Runtime-based (.NETPortable,Version=v4.5|6,Profile=*), it would work so long as you referenced all the packages needed by the PCL (eg: System.ServiceModel.*, System.Runtime.Serialization.*, etc). If the PCL only used assemblies which were part of .NETCoreApp then you wouldn't need to add those additional references.

If the PCL happened to only use .NET API and was mscorlib-based (.NETPortable,Version=v4.0,Profile=*) a similar constraint applied and you would also need to reference Microsoft.NETCore.Portable.Compatibility to bring in Facades for things like System.dll and System.Core.dll.

The latter scenario (mscorlib-based PCL) gets better in .NETCoreApp2.0, as we have included those facades in the framework. There is still the case of things that aren't inbox in .NETCoreApp (eg: System.ServiceModel.*) and will require a manual reference to make things work.

NETStandard-based PCLs on the other-hand work with no additional changes and all references are guaranteed to be either provided by the framework or referenced by the package.

The thing that's preventing you from referencing (the error you mentioned in the issue body) is NuGet, and it is doing so because of these rough incompatibilities that I mention. The linked issue has numerous workarounds for that particular old package. There's also a newer package that is compatible with NETStandard: System.Composition.

ericstj avatar Jun 19 '17 16:06 ericstj

@ericstj , Yes I used package Microsoft.NETCore.Portable.Compatibility and one more thing I needed to do, to get this done is, to copy portable folder from C:\program files(x86)\Microsoft visual studio\2017\community\MSBuild\ to C:\Program Files\dotnet\sdk\1.0.4\Microsoft\

Is this a correct way?

avikenjale avatar Jun 21 '17 14:06 avikenjale

@avikenjale that looks like you were trying to build a PCL with the CLI tools. I don't think that's supported but @livarcocc or @srivatsn would no better. You don't need to do that if all you want to do is reference a PCL in a netcoreapp/netstandard project. I believe the only supported way to build a profile-based PCL is to use the classic CSProj produced by the template and build with either VisualStudio or MSBuild.

ericstj avatar Jun 21 '17 16:06 ericstj

@ericstj , Ahhh, now I remember, using VS 2017, it was working fine, however when I was trying to build same using dotnet command (and using VS Code IDE), it was failing so that time I copied this portable folder under dotnet folder.

This way I can build PCL+.netcoreapp+netstandard , using MSBuild or dotnet build commands, either way.

avikenjale avatar Jun 21 '17 16:06 avikenjale

Yeah. Dotnet CLI cannot officially build the the old projects, but it doesn't block it. As a result, things appear to work, until they don't. Portable is one example where it fails but there are many others. I filed https://github.com/dotnet/cli/issues/6732 because of this.

ericstj avatar Jun 21 '17 16:06 ericstj

Closing non-sdk projects are "now" supported with dotnet build. Not sure when exactly support was added.

ViktorHofer avatar Aug 26 '18 19:08 ViktorHofer