last time in our template mini series we
talked about how to create your own
custom template
but how do you get it to actually show
up in visual studio find out on this
episode of visual studio toolbox
hey everyone welcome back to another
episode of visual studio toolbox
i'm your host leslie richardson and i'm
joined yet again by
senior program manager saya hashini
welcome back
hello thanks for having me all right so
this time around we're going to take
the net template that we created in the
previous episode
and get it to work for visual studio
right
that's right that's right so yeah so
when you create a template for
net new there are a couple
customizations that need to be made to
get it to appear in visual studio
so we're gonna we're gonna those are
pretty simple and should be pretty quick
so we're gonna
kind of run through those real quick and
uh we'll show
we'll show exercising that uh project
template and visual studio
as well all right
all right let's go and get started here
so i've got the that solution opened up
that we've been kind of working on here
so now um
whenever so when when using the template
engine to create a template
um i showed you the basics of how to get
a template working for
net new but what we need to do is
actually modify we're going to add a
couple additional
files here so let me go into my samples
here and the source
under content and the template config we
can see there's a couple additional
files so the ide.host.json file
that's the one that we'll be adding here
so i'm going to go ahead and go into
that
we're going to copy the the schema file
for the schema declaration for that
let me go and add
i'll go and add um
i'll go and add this to the to the
correct location here so my console one
let's get rid of that other one all
right i'm going to create
the the id.host.json file here
alrighty and drag this back into
visual studio itself so i can start
working on that
i'm going to go ahead and add that
schema declaration there
so now what the with the ide.host.json
what this does
is this is an indication that you want
your template to appear
in the various different ides that
support it so
those those ids that support this are
visual studio 2019
and um and and also visual studio for
mac
and also i think jetbrains writer has
support for these custom templates as
well
and uh one thing that i'm not sure if we
covered yet was
you know how do i turn on the feature uh
for your.net new templates to
show up in visual studio so you'll go
into tools options and then go down to
preview features
and then scroll down to where you see
showall.net core templates
so definitely make sure that that's
checked and and then
the 16.9 that should be checked by
default
all right so i went ahead and i added
this id.host.json file so without
if this file is not there visual studio
believes that this template hasn't been
designed
to be used within visual studio so they
just won't appear
unless you create this file all right so
we did that now let's go back
let's take a look at where we're at okay
so now what i need to do is i need to go
ahead and rebuild
i need to rebuild the nuget package so
that way it will have the
the ide.host.json file there so i've
rebuilt it
and i'm just going to go ahead and
install this as well
so it's a net new install and then path
to negative package file
it's going to install that
you can see that it has been
successfully installed let me restart my
visual studio here
so yeah whenever you install a new uh
template you'll have to restart visual
studio to get it to appear
all right so let me just do let me clear
out my filter here
earlier we talked about the
classifications so this is where the
classifications will appear and that's
how you can filter them
so for example i can filter the console
because that's what i had but that's
what i indicated in my
template.json and now we can see i've
got my project here
but what i'm noticing is you know it's
just got the regular kind of default
icon here
and you know that's not really the right
experience i'm just going to go ahead
and close out of this we'll add a
different icon
and then come back again so let's go
ahead and close out of that
i'm just going to go ahead and download
the icon.png
file that's here and in my samples
repository here
and this this image
it has to be you know in or under the
template.json
sorry.template.config folder there so i
put it directly in
the template.config folder there
let me open up that file one more time
that's it now i'm going to go ahead and
edit my ide.host.json file
to add the icon property here
icon and then it was just um i think it
was just icon.png if i'm not mistaken
a very inspiring name yeah very very
let me go ahead and uh save that so what
we'll do is we're going to just redo the
whole thing here so i'm going to reset
my
templates then i'm going to uh
to repack it and then i'm going to go
ahead and install this
and uh if if i was doing this myself i
would just uh wrap these three commands
into one so i would just have one
command was reset template semicolon
and then this command semicolon and then
this command and then
when you hit enter it will just run all
three at the same time
all right so now um we've we've
reinstalled our template and hopefully
we've got that kind of custom icon
appearing there so let's go ahead and
fire that up so it's going to create a
new project
all right so here we go so now we can
see i've got the the custom icon that
appears there it looks like some kind of
screwdrivers or something looks very
legit yeah yeah okay so here's here's
another thing that i'm noticing here so
now
for the project name i just get project
five you know maybe i want to kind of
customize that a little bit as well so
let me show you how you can do that
so that is actually with inside the
template.json file so let me open that
guy back up one more time
so template.json all right there's
another property that we can add here
it's default name so i'll say the
default name is
just console and then visual studio will
add to 1 2 and 3 basically
let's go ahead and close out of that
b packet and then reinstall it
all right let's try it and uh definitely
make sure to close
visual studio while you're kind of doing
this
if i had kept visual studio open at that
time then then these changes would not
appear
so we saw earlier it said you know like
project one or something like that but
now i'm getting something that's a
little bit better here console one
we'll say demo demo console let's go and
create this project
all right let's go ahead and just uh
debug this
all right hello from demo console so
that's exactly what we expected there
and
you know we we had kind of a first class
support in visual studio with that kind
of custom icon and customizing the
project name and
and you know templates that are created
with dot net new
you know they're they're first class
citizen just like templates that have
been
uh created by microsoft themselves so in
the upcoming videos we'll show how to do
parameters and
and kind of make these templates even
more better that's exciting
and i mean just that template json file
in general just seems so important it's
like the blueprint for
all of it that's right that's right and
you know once again whenever you're
editing one of those json files you know
whether it's the
template.json or the ide.host.json
you always want to make sure to have the
correct schema declaration
uh defined in there so you'll get the
right kind of errors and warnings and
and also the hit the hints with the
intellisense makes sense
great well i can't wait to see what
we're going to do next time with the
templates as you mentioned we're going
to be talking about parameters and
other cool things so until then happy
[Music]
coding
Wednesday, February 4, 2026
Create a .NET Core Project Template for Visual Studio
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment