ligershark / sidewafflev2

Other
30 stars 11 forks source link

How to use SIdeWaffle to make a dotnet solution template backwards-compatible #51

Open VacuumBreather opened 2 years ago

VacuumBreather commented 2 years ago

I'm trying to get a dotnet solution template with a slightly complex folder structure to be compatible with VS2019 (without the preview feature) and if possible with VS2017

The solution looks like this.

MyProject.sln -Src MyProject-shared.csproj SharedFilesA SharedFileB -Platforms -android MyProject-android.csproj FileA -ios MyProject-ios.csproj FileB -macos MyProject-macos.csproj FileC -net50 MyProject-net50.csproj FileD

Src and Platforms are also represented by solution folders.

I'm trying to find ways to ensure backawards compatibility but have a hard time getting this to work. The old .vstemplate + wizard way seemed to make it impossible to achieve this structure which is why I moved to dotnet template engine. but that is not backwards compatible enough for the customer. I have tried Sidewaffle but am not sure how to use it to create such a template I've also tried this project (https://github.com/Jjagg/dotnet-vstemplate) but ran into errors, it seems that project cannot handle solution templates

Any help would be very much appreciated.

sayedihashimi commented 2 years ago

Hi @VacuumBreather have you seen my videos linked below, they may be helpful.

VacuumBreather commented 2 years ago

I have watched them. unfortunately they didn't help me achieve this result.

sayedihashimi commented 2 years ago

@VacuumBreather do you have a sample that you're working on that I can try out?

VacuumBreather commented 2 years ago

I'm having the most trouble understanding how the vstemplate files need to be set up. Do there need to be such files for each project or just for the solution, if only for the solution, how do I generate those. In the video you just move a project vstemplate one level higher without modifiying it? That seems to make no sense. Also the Sidewaffle Vsix project throws an error. I'm not sure how to turn the existing template.json based solution template into something sidewaffle understands, or how to generate the vstemplate files.

I attached a sample

Projects.zip

VacuumBreather commented 2 years ago

Ideally the resulting VSIX will be installable in VS2017, 2019 and 2022 and the templates work in all three. I'm currently only getting it barely to work in 2019 but getting a HRESULT error on project creation, so I'm doing something wrong. I left the vstemplate file out of the zip because I don't know hot to generate it.

VacuumBreather commented 2 years ago

This is my current progress. I'm getting an error in VS2019 (with the preview feature of showing .NET Core templates deactivated) and it doesn't work at all in 2017.

Templates.zip

This is the error in 2019 upon project creation. The error shows up after the project seems to be fully created already, but then I'm stuck in the create project dialog and can only cancel (which leaves me with a working solution however) error

In 2017 it shows up in the menu, but on creation complains that it cannot find any template with the specified GroupID.

These two errors might be the same thing, I'm not sure. The group ID seems to be correctly set everywhere, I'm not sure what causes this.

Edit: I should also mention that this error happens after the VSIX has been properly installed, not on the testbed instance. I also deactivate the "show .NET Core templates in new project dialog" since that is a test feature my customer does not want to rely on in VS2019 to make the template show up. Not sure if that causes the error or not.

VacuumBreather commented 2 years ago

I think I found the reason for the error. It occurs the scond I'm switching

  "tags": {
    "language": "C#",
    "type": "project"
  },

to

  "tags": {
    "language": "C#",
    "type": "solution"
  },

in the template.json

However this change is necessary since I need the solution file to be used as defined in the template, instead of a generated solution file. There are solution folders in there and other things that need to be the way they're set up in the templated solution file.

However this seems to be causing this error to occur. I also can't get even the simplest multi-project template to work properly in VS2017. I'm either getting an empty solution or a message that the SideWaffle package wasn't correctly loaded (which I saw is an already reported issue)

sayedihashimi commented 2 years ago

With VS, it tries to use the solution file created. I'm not sure if the Wizard supports "solution" templates. @phenning, does the wizard support this?

VacuumBreather commented 2 years ago

Also can you tell me what the default value for "Show all .NET Core templates in New Project window" experimental setting is in a fresh install for VS2019? Is it by default on or off? I'd simply use a standard dotnet template but my customer really doesn't like that we have to rely on that being active... that's why I'm trying to get it to work in SideWaffle to begin with. but if that doesn't support solution templates, this might not be an option either. The only alternative then is to go back to old .vstemplate type templates and IWizard implementations, which make this sort of folder layout and solution setup not exactly easy to achieve either. Right now I'm struggling to find out what's the easiest way to achieve this end result at least in VS2019 and VS2022, but it's already taking a lot longer than my customer is happy with. It seems for both ways of making a template this complex end result is an edge case that's very hard to achieve.

phenning commented 2 years ago

With VS, it tries to use the solution file created. I'm not sure if the Wizard supports "solution" templates. @phenning, does the wizard support this?

The wizard does appear to support this. We do most of the heavy lifting in a shared component that both the wizard and template provider implementations use.

phenning commented 2 years ago

Also can you tell me what the default value for "Show all .NET Core templates in New Project window" experimental setting is in a fresh install for VS2019? Is it by default on or off? ...

It is on by default in 16.9 and later, and off in version 16.8.

In Visual Studio 2022, the new template experience will always be available.

yassinebennani commented 1 year ago

Hello @sayedihashimi @phenning

Please I need your help guys I'm struggling to make the custom wizard working with dotnet template in visual studio 2022 17.4.1, I followed every necessary step and I analyzed all your repositories and videos (I really did) but I think there is something wrong, I can see my template while debugging my vsix project but the wizard is not getting invoked when I create the project. (the same wizard is getting invoked when I use a visual studio project template)

My $groupid$ is matching the identitygroup field from template.json My TemplateID is matching the identity field from template.json My wizard assembly is signed My .nupkg is getting installed to ProjectTemplates/ via the package definition file My template.config folder contains also the vstemplate file My template.zip is getting installed to the right location and contains the 3 files vstemplate, template.json and the icon.

I confirm that I can create my project while debugging the vsix project and the output is like expected but the wizard is not getting invoked.

template.zip

Please save my week guys I'm blocked.

Thank you very much.