ServiceModel lib usage

Hi,
Our custom made ERP is using ServiceStack (.NET Framework) as a basis. We are using a classical ServiceStack recommended structure.
So, we have a MyProject.ServiceInterface (containing API layer and all operations) and a MyProject.ServiceModel (containing all dtos) projects.

Another projects need to request this ERP and I want to share the MyProject.ServiceModel library so they can reference it to request ERP the easiest way.

A problem I have is that MyProject.ServiceModel is compiled using .Net Framework 4.6.2 as target Framework.
The projects destinated to use MyProject.ServiceModel library are compiled using .Net Framework 4.5 as target Framework.

I would like to know if it’s possible to compile MyProject.ServiceModel library using a lower version of .NET Framework, without changing target framework for MyProject.ServiceInterface.

Thank you.

That would depend on the version of ServiceStack.Interfaces you’re using, since you’re only targeting v4.6.2 I’m assuming you’re only referencing ServiceStack v5.x which supports .NET v4.5 so you should be able to lower the target of the ServiceModel project to target net45 to support both .NET v4.6.2 and .NET v4.5 Apps.

Otherwise when the same project needs to have multiple targets with different packages you can multi-target and maintain different references per target, e.g:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net462;net45</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
    <PackageReference Include="ServiceStack.Interfaces" Version="5.*" />
  </ItemGroup>

  <!-- ... -->
</Project>
1 Like

Thank you very much Demis. This is crystal clear!

1 Like