question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Checkup on the Microsoft.TemplateEngine.Cli circular dependency: dotnet/sdk -> dotnet/templating -> dotnet/sdk

See original GitHub issue

Looking at v5.0.0, this package reference causes a circular dependency:

https://github.com/dotnet/templating/blob/31980633108a1bef00c798136fcd30a873c90fa3/src/Microsoft.TemplateEngine.Cli/Microsoft.TemplateEngine.Cli.csproj#L22

Circularity:

  • dotnet/sdk depends on Microsoft.TemplateEngine.Cli, and produces Microsoft.DotNet.TemplateLocator.
  • dotnet/templating depends on Microsoft.DotNet.TemplateLocator, and produces Microsoft.TemplateEngine.Cli.

Since dotnet/templating is “earlier” in the .NET SDK build graph (templating -> sdk -> installer), it ends up depending on an earlier version of the package than the one we actually ship. (This shows up above as dotnet/templating v5.0.0 depending on a 5.0.0-rc.1 package!)

This isn’t inherently a problem. It looks like dotnet/templating is compiling against Microsoft.DotNet.TemplateLocator for the API, but a newer version is inserted in the SDK that is actually used at runtime instead. In source-build, we can handle this by generating a ref-only version of Microsoft.DotNet.TemplateLocator/5.0.100-rc.1.20421.19 to have dotnet/templating compile against rather than having a dependency cycle.

Note that cycles do have inherent risk, this isn’t just a source-build issue. 😄 If the TemplateLocator API has breaking changes, dotnet/templating may produce a library that can’t actually run in the SDK. This is particularly risky with unstable/prerelease/rc versions of APIs.


A few questions about this:

  1. Is this cycle intentional? (Is one of these libraries actually in the wrong repo?)
  2. Can source-build rely on dotnet/templating release/5.0 always using Microsoft.DotNet.TemplateLocator/5.0.100-rc.1.20421.19, never updating?
    • Updating this causes source-build significant maintenance effort because we have to put together a new ref-only version of the package’s new version.

@vlada-shubina /cc @mmitche FYI on cycle.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
vlada-shubinacommented, Nov 18, 2020

Agreed:

  • Template Engine to define ITemplateLocator interface (1 method) and IOptionalSdkTemplatePackageInfo interface and change Microsoft.TemplateEngine.Cli to use it instead Microsoft.DotNet.TemplateLocator members
  • once done SDK will inject implemetation of ITemplateLocator from Microsoft.DotNet.TemplateLocator when calling TE in the shim

Since the fix is internal and not urgent, potential timeline is Q1 '21.

1reaction
vlada-shubinacommented, Nov 11, 2020

Adding @wli3

Microsoft.DotNet.TemplateLocator is used for optional workloads which are not yet live, that’s the reason probably why the version is hardcoded, as it was just used for initial implementation.

imo it is not possible to move Microsoft.DotNet.TemplateLocator to templating as it is reusing SDK features, however probably instead of calling it from Microsoft.TemplateEngine.Cli to determine packages to install/uninstall we can inject this information from sdk when instantiating new command , thus avoiding circular dependency. At first glance I don’t see any dependency on template engine for template locator to evaluate packages to install/uninstall, but I might be wrong.

Related issue: https://github.com/dotnet/templating/pull/2614

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular dependency detected on resource - Microsoft Q&A
In your template, find the resource identified in the circular dependency. For that resource, examine the dependsOn property and any uses of the ......
Read more >
Custom templates for dotnet new - .NET CLI
The template engine offers features that allow you to replace values, include and exclude files, and execute custom processing operations when ...
Read more >
There is a circular dependency in the target ...
We are using Code first asp.net application (.net frame work 4.7.2), and able to run update-database command from visual studio.
Read more >
Circular dependency detected on resource
When attempting to deploy a template i'm getting th folloiwng error. ... I've looked in "DependsOn" however i don't know what i'm looking...
Read more >
Code to check the circular dependency between classes
Circular dependency between classes I've tried something this works well, it needs to be checked whether it's correct or if anyone can help ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found