AArnott / CodeGeneration.Roslyn

Assists in performing Roslyn-based code generation during a build.
Microsoft Public License
408 stars 59 forks source link

What happens if multiple librarys requirer `DotNetCliToolReference ` #65

Closed LokiMidgard closed 6 years ago

LokiMidgard commented 6 years ago

It is required to use following statement in his project file:

  <DotNetCliToolReference Include="dotnet-codegen" Version="0.4.11" />

What happens if a consumer consumes two librarys that depend on different versions of the dotnet-codegen tool. In worst case one that has breaking changes, so that just using the newer on does not help.

amis92 commented 6 years ago

From the docs https://docs.microsoft.com/en-us/dotnet/core/tools/extensibility#building-tools

These kinds of tools have a dependency graph that is completely separate from the dependency graph of the project that uses them. The restore process first restores the project's dependencies and then restores each of the tools and their dependencies.

AArnott commented 6 years ago

@amis92: notwithstanding that the tool itself has its own dependency graph, a single project cannot have two versions of the same tool. And even if it could, the msbuild task wouldn't know which one to invoke.

This isn't unique to DotNetCliToolReference either. If there were two MSBuild task versions that were incompatible, it would fail to build because msbuild can only load a particular msbuild task once -- it has no concept of multiple versions of a task even across projects.

That said, if you have two libraries that need different versions of the tool, they can go ahead and reference the version they need. That need not and does not propagate to a common project that references both of these libraries.