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.

Item templates should pick correct language from project

See original GitHub issue

Is your feature request related to a problem? Please describe.

When using a item template inside a F# project, e.g. dotnet new avalonia.templatedcontrol I would expect that the option -lang=F# would not be required but it is. So it is using the C# version by default when the -lang=F# was omitted/forgotten.

Describe the solution you’d like.

The solution should be that the templating engine should detect that the item template is added to a project of a known language, when the item template has multiple matching identities with different lang tags the correct one should be picked.

Additional context

Somewhat related to: #5358

Also I am aware of #2684 but I don’t think that is a solution when e.g. you mostly use C# but only sometimes F#.

Issue Analytics

  • State:open
  • Created 9 months ago
  • Reactions:1
  • Comments:13 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
YuliiaKovalovacommented, Jan 16, 2023

Hi everyone,

I have contacted the author of the https://github.com/microsoft/VSProjectSystem/blob/master/doc/overview/project_capabilities.md - the document is outdated. F# is added to project capabilities.

The problem is on the templating side - the required information isn’t retrieved during the evaluation phase [ProjectCapabilityConstraint.cs](https://github.com/dotnet/sdk/blob/3eea35e0d77f9a1bc418a364805ff89df818e371/src/Cli/dotnet/commands/dotnet-new/MSBuildEvaluation/ProjectCapabilityConstraint.cs#:~:text=static void-,AddProjectCapabilities,-(HashSet%3C )

We are working on fixing the issue.

0reactions
vlada-shubinacommented, May 18, 2023

After impediment is resolved, the work in template resolution still needs to be done. Picking up correct template language based on project context is not available yet, and template resolution logic should be adjusted to take constraints into account.

Relevant code managing constraints (https://github.com/dotnet/sdk/blob/11f4fee47293e8c9dae5fa902074eb26062d8f99/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs#L158-L168) happens only when single template is defined.

It should be moved earlier in the invocation cycle, potentially in this method: https://github.com/dotnet/sdk/blob/11f4fee47293e8c9dae5fa902074eb26062d8f99/src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs#L363-L385

If constraints are satisfied only for single template, it should be preferred. This should fix auto language pick-up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Templates for projects and files - Visual Studio (Windows)
Project and item templates are reusable stubs that give you some basic code and structure to customize for your own purposes. Typically, you ......
Read more >
Reusable Project And Item Templates using Visual Studio ...
If a template is identical for multiple languages, providing a value of true in this element will allow the user to choose a...
Read more >
Visual Studio Item Templates, Custom Wizards and VSIX ...
Choose correct project types​​ These are all found under the Visual C# > Extensibility category. Yes even though you're creating a C++, F#...
Read more >
How to get item templates working in visual studio 2017
On the File menu, click Export Template. Click Item Template, select the project that contains the item, and click Next. Select the item...
Read more >
Professional Template Languages - PyCharm
Use this page to select the template language to be used in each of the projects opened in the same window, specify template...
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