.NET Boxed Visual Studio Integration

Visual Studio

A few weeks ago Scott Hanselman blogged about creating dotnet new based projects directly from Visual Studio. Unfortunately, at that time Visual Studio 16.9 didn't properly support full solution templates and only supported project templates.

Happily, Microsoft just released Visual Studio 16.10 and one of the things they didn't talk about was that it now adds a user interface for creating solutions from dotnet new templates.

Given that I author the .NET Boxed solution and item templates, I thought I'd run through how it's done.

Step by Step

The first step is to install a dotnet new based solution/project/item template NuGet package. Sadly, this step is still command line only but there are plans to add a UI so you can search for and install templates all through Visual Studio.

dotnet new --install Boxed.Templates

Next we can fire up Visual Studio and go to the 'New Project' dialogue. You can select '.NET Boxed' from the 'Project type' menu on the top right to see all .NET Boxed project templates.

Visual Studio new project dialogue

The next step is where we can give the project a name as usual and decide where we want to store it on disk.

Visual Studio configure project dialogue

Finally, we get to the new interesting bit, where we can select from the many options that .NET Boxed templates provide:

Visual Studio additional information dialogue

Finally, we can hit 'Create' and start getting productive in Visual Studio.

New Visual Studio solution

That's it! Simple isn't it.

Web Mentions

What's this?

0 Replies

GitHub Comments

mike1880
(edited )

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.

mike1880

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.

oising

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

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).

m-meier

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

@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
(edited )

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

@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

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.."

m-meier

@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

@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?