RehanSaeed / rehansaeed.github.io

Muhammad Rehan Saeed's Blog
https://rehansaeed.com
30 stars 6 forks source link

[Comment] .NET Boxed Visual Studio Integration #359

Open RehanSaeed opened 3 years ago

RehanSaeed commented 3 years ago

https://rehansaeed.com/dotnet-boxed-visual-studio-integration/

mike1880 commented 3 years ago

Doesn't work on VS 2019 16.10 for me. Works on 2019 16.11 Preview.

Edit: no, I tell a lie. It doesn't work for me in 16.11 either. It creates a minimal solution file and a project folder then apparently dies without creating any other project files.

RehanSaeed commented 3 years ago

@mike1880 Which project did you try?

mike1880 commented 3 years ago

Asp.Net Core API Boxed. No source control, no reverse proxy, no analytics, cloud provider Azure, xml formatter XMLSerializer. I have .Net 6.0 installed which sometimes causes problems (e.g. WinUI projects) if that's any help.

RehanSaeed commented 3 years ago

Thanks @mike1880, that seems like a bug in VS so I raised https://github.com/sayedihashimi/template-sample/issues/29. Lets see what answer we get. In the mean time, you can continue to use the CLI which does work.

lohithgn commented 3 years ago

@RehanSaeed i left a comment on issue https://github.com/sayedihashimi/template-sample/issues/29 ....

basically the template works from VS when we enter values to all the fields...

oising commented 3 years ago

Doesn't appear in the dropdown for project types at all in v16.10 (final). I tried uninstalling and reinstalling the templates (because I had previously installed them for earlier version of VS).

Btw, this might help, but I have both VS 2019 16.10 and 16.11 (preview) installed.

sayedihashimi commented 3 years ago

It should work in 16.10+, when a blank solution is created that happens because the template has a required parameter, that has no default value, and is not provided by the user. We should update Visual Studio to block project creation at that time. @RehanSaeed I would recommend that you provide default values for all required parameters. Even after we block project creation for this case, it won't be a great experience for users, especially since the template has lots of parameters (it may be difficult for the user to find the missing parameter that needs to be filled in).

RehanSaeed commented 3 years ago

This now seems to be fixed in Boxed.Templates version 6.3.3. Thanks for identifying the issue.

m-meier commented 3 years ago

I have the same problem as @oising, none of the templates appear in the new project dialog (16.11 preview). I tried with and without the preview flag (Show all .NET Core templates in the New Project dialog). "dotnet new" shows the templates.

RehanSaeed commented 3 years ago

@oising @m-meier You need the latest version of the template installed for it to be displayed. Can you check that you have the latest installed by running:

dotnet new --update-check
dotnet new --update-apply

Alternatively:

dotnet new --uninstall Boxed.Templates
dotnet new --install Boxed.Templates
m-meier commented 3 years ago

I already had 6.3.3. I tried reinstalling (and even a system reboot), but nothing worked.

PS U:\> dotnet new --update-check
All template packages are up-to-date.
PS U:\> dotnet new --uninstall Boxed.Templates
Success: Boxed.Templates::6.3.3 was uninstalled.
PS U:\> dotnet new --install Boxed.Templates
The following template packages will be installed:
  Boxed.Templates

Success: Boxed.Templates::6.3.3 installed the following templates:
Template Name               Short Name     Language  Tags
--------------------------  -------------  --------  ----------------------------
ASP.NET Core API Boxed      api            [C#]      .NET Boxed/Cloud/Service/Web
ASP.NET Core GraphQL Boxed  graphql        [C#]      .NET Boxed/Cloud/Service/Web
ASP.NET Core Orleans Boxed  orleans        [C#]      .NET Boxed/Cloud/Service/Web
NuGet Package Boxed         nuget          [C#]      .NET Boxed/Library
RehanSaeed commented 3 years ago

@sayedihashimi Can we expect dotnet new templates to work in VS 16.11 preview? If you have 16.11 preview installed, can we expect 16.10 to still work?

mike1880 commented 3 years ago

I still don't get the templates appearing in 16.10, only in 16.11. I can generate a solution in 16.11 but it won't build. The projects are generated as .Net 5.0 but it looks to be referencing .Net 6.0 in build; there are around 70 or so CS8032 errors, for example: "An instance of analyzer Microsoft.CodeAnalysis.MakeFieldReadonly.MakeFieldReadonlyDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\6.0.100-preview.4.21255.9\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CodeStyle.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, {app name} PublicKeyToken={value}' or one of its dependencies. The system cannot find the file specified.."

RehanSaeed commented 3 years ago

Thanks @mike1880.

@sayedihashimi Is there some way I can stop VS 16.11 retargeting the TFM to .Net 6.0?

m-meier commented 3 years ago

@RehanSaeed: Now the templates appear for me. I added a visual studio feature (IIS debugging), afterwards the templates were available. I guess the installation cleared some cache or something similar.

I got the solution running on kestrel with 16.11 by switching the build target to 6.0, disabling build time code analysis and fixing an error from a non-nullable reference type and access to ActionContext (derefence from a possible null reference).

sayedihashimi commented 3 years ago

@RehanSaeed

@sayedihashimi Is there some way I can stop VS 16.11 retargeting the TFM to .Net 6.0?

Can you explain more what you are seeing? Are you saying that the user selected .NET 5 as the TFM and then VS used .net 6 instead?