Azure / azure-cosmos-dotnet-v2

Contains samples and utilities relating to the Azure Cosmos DB .NET SDK
MIT License
579 stars 837 forks source link

NuGet package design makes it impossible to reference ChangefeedProcessor in hybrid .NET/netstadard solutions #521

Open eiriktsarpalis opened 6 years ago

eiriktsarpalis commented 6 years ago

My team is working on a net471 solution that makes heavy use of the DocumentDB and ChangefeedProcessor SDKs. We're looking at migrating parts of the solution to netstandard2.0 and netcoreapp2.0, however we are blocked by build issues triggered by the peculiar dependency structure that your nuget packages are employing (namely, different nuget packages for the netstandard and net4x core SDKs, which are both referenced by a multi-targeted release of the changefeed SDK).

Here is a minimal reproduction that highlights the problem

Building results in the following error:

error CS0433: The type 'ConsistencyLevel' exists in both 'Microsoft.Azure.DocumentDB.Core, Version=1.9.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Microsoft.Azure.Documents.Client, Version=1.20.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I cannot make this error go away unless I either remove the changefeedprocessor reference from the netstandard library or upgrade the console application to netcoreapp. It is blocking us from upgrading our shared libraries to netstandard.

I believe that this error would go away if you were to also multi-target the core SDK. Perhaps something to consider in anticipation of the 2.0 release?

ealsur commented 6 years ago

Are you referencing the Microsoft.Azure.DocumentDB.Core for some particular feature? The Microsoft.Azure.DocumentDB.ChangeFeedProcessor already contains a reference to it.

eiriktsarpalis commented 6 years ago

Yes, I need to reference both. The problem however is that Microsoft.Azure.DocumentDb.ChangefeedProcessor also forces Microsoft.Azure.DocumentDB to be loaded. Please see the reproduction solution.

ealsur commented 6 years ago

Correct, this is because your main project is targeting net471. The Change Feed Processor is using the Cosmos DB SDK Full Framework package for net471 and the Core package for netstandard2.0, it's the only way to be able to multi-target as the SDK has two different projects at this moment.

As you said, this would be solved if the SDK were a single package, which is currently being worked on.

The only workaround I see is to remove the Microsoft.Azure.DocumentDB.Core explicit reference and let the chain resolve to the package that works in the consuming app.

If you app is net471 it will resolve to the Full Framework package, and if your app is netcoreapp it will resolve to the Core package.

eiriktsarpalis commented 6 years ago

The only workaround I see is to remove the Microsoft.Azure.DocumentDB.Core explicit reference and let the chain resolve to the package that works in the consuming app.

That is true, however in the real codebase we need to reference the cosmos db sdk in the shared netstandard class library.

tjrobinson commented 5 years ago

@eiriktsarpalis We are doing this and it seems to be working out ok:

  <ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
    <PackageReference Include="Microsoft.Azure.DocumentDB" Version="2.1.3" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
    <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.1.3" />
  </ItemGroup>