>> Hello, Sayed Hashimi here,
back with another Visual Studio for Mac tips and tricks video.
In today's video, I'm going to show you how you can improve
your productivity using the Navigate To feature.
Navigate To is similar to
the Quick Launch feature that you might
have used in Visual Studio for Windows.
I'm going to demonstrate this to you today by working on an
existing ASP.NET core web app that I've created previously.
So, first let me introduce you to Navigate To,
Navigate To is found here at
the top right-hand corner of Visual Studio for Mac,
and using Navigate To,
you can explore your solution,
your IDE, run commands and more.
If I expand this dropdown,
you can see that Navigate To has special support for files, types,
members and commands, and we're
going to go through each one of those in the video today.
All right.
Let me introduce you to the application
that we're going to be working on today.
It's a solution that consists of four projects.
We've got an ASP.NET Core, Web API project,
a shared class library,
and then an ASP.NET Core Razor Webpages project.
I've got the application running here.
So, let me go ahead and switch to
the browser and I'll show you that.
So, this is a web application that's available that will
show you the different template
that are available for .NETNew,
and you can visit
this web application by going to.NetNew.Azurewebsites.net.
All right. So, as I'm looking through here,
basically each one of these headings
represents a new Git package that
consists of one or more templates,
in the template world we call these template packs.
As I'm browsing this website,
I can see that there must be some bug here,
because on certain lines I'm seeing empty bullet points here.
So, that's what we're going to take a look at
today and we're going to go and try and fix that,
and we're going to try to use Navigate To during this process.
So, now I'll switch back to
Visual Studio for Mac and we'll get started.
The first thing I need to do is stop
the application which is running,
and to get to Navigate To,
you can also use the keyboard shortcut Command.
which I'll mostly be using today.
All right.
So, first I want to stop the application.
So, I'm simply going to press "Stop" here.
So, I invoke stop and we can see that
the "Stop" button has turned
into a "Play" button again. All right.
So, now we've stopped the application and we need
to try and figure out how can we fix this bug.
Let me give you a high-level overview
of what this application does.
So, we've got a Razor web pages application
that calls into an API project,
and by default on the index page,
it's going to make a call in to the API project to get
the result of the template packs which are available,
and that's what I want to look for,
that's where I want to start looking for my debugging,
is inside that API call.
So, now, I want to navigate to
the controller that's responsible for that,
and I'm going to search for a type here,
so prefix it with t and say template pack controller,
that's the controller that's called when
the API goes to the template packs page,
and the Git method here is basically what's going to be called.
So, we can see that it returns template packs,
and in the constructor,
the template packs are
initialized by calling template pack create from file.
So, I can right-click "Create from file"
and go to declaration if I wanted to,
but I can also do a similar thing with Navigate To.
I can say I'm looking for a member called "Create from file".
So, we go to "Create from file", this is where we're at.
If I was to go through and look through here,
we can see that Create from file it will get
the JSON result of
the template report and then create an object based from that.
The main call is here, "Create from text".
So, what I want to do is,
I want to go ahead and start debugging my application,
and then I'll show you how we can stop at this point.
So, I'll use command.
and then I'm going to run a command that's called Start.
So, it'll say, "Start debugging."
We're going to let the word go
ahead and let the debugger start here,
and then what I'll do is, I'll set
a break point and
create from file and then we'll refresh the browser.
Wait for that breakpoint to get hit.
So, now what I'll do is I'll go down to "Create from text",
and then I'm going to execute another command
called Run to Cursor.
So, this will bring the debugger all the
way down to the line that's currently selected.
So, now let's go ahead and inspect
the result here and see if there's
any problems that might result in those empty bullet points.
So, we have the list of template packs,
and now we want to go and inspect
the templates that are available for these.
So, let me go into the first template pack.
Here we can see we've got the
single-page application templates for ASP.NET Core,
and if I drill into the templates list
and then expand out the first one,
I can see now I have a list of
values here which is essentially empty, so there null.
Then the second one has actual content,
and then if I expand the third one,
we're seeing more nulls here again.
So, this is obviously the problem.
So, let me go ahead and stop debugging.
So, I'll do Command.cstop,
now we've stopped debugging.
So, what we need to do is filter the result
and don't include any templates which
are which are essentially empty.
I've created a snippet that I am going to
invoke that will solve this problem for us.
So, here we've got the code and we're going to filter
out and remove any template which does not have a name.
All right. So, hopefully that's going to fix our problem.
Let me go in and start debugging the application again.
I'm going to remove this breakpoint.
Go down to "Toggle Breakpoint", and then continue.
All right, here we can see the application is now running,
and we have successfully removed
the empty bullet points that were here previously.
All right. So, now we fixed that bug.
So, let me go back to Visual Studio for Mac.
I'll stop debugging again,
and now we're pretty much ready.
We've made this bug fix,
now we need to go ahead and commit it back to our repository.
It'll do [inaudible] and commit.
Expand the modified to take a look at the results.
We can see that's correct. It looks good.
I'm going to go ahead and click "Commit" here.
Okay. So, now, I've committed that bug fix and we're ready to go.
We could also push that to a remote repository if we wanted to,
but I'm not going to do that here for this case.
So now, let me go back to Navigate To and I'll show
you some other neat features which are available there.
We can see that from way that we fix this particular bug,
we took the result from deserialize object,
from the template report,
and then just filtered out those templates.
But let's go take a look at that file and
see if those nulls
are present there or is there some other bug as well?
And I can't remember where I have that file,
but I do remember that inside the file,
there was a property
called Extract path, and that's pretty unique.
So, let me go and search for that.
So, I'm going to use Navigate To for that.
So I'll say, Extract path,
and then I'll select "Search and solution".
So here's the results that I found.
Here's my template report.
As we can see, there are no entries here.
This application just consumes this template report,
it doesn't actually generate it.
So, we're not able to actually fix their problem here,
but at least we know there's
no additional bug with inside the application itself. All right.
Now, let's take a look at some other features that we can invoke
from the Navigate To. So, I'll go back into it.
Let's say now we want to add a new Git package to this project,
for example, if I want to add the Auto Mapper in the Git package,
I can search for the name Auto Mapper,
and then go down to search packages,
and then I could select Auto Mapper or
whatever that package is I now wanted to add,
and then select "Add Package".
Okay. So, now it has successfully
installed the.Auto Mapper package into my project,
and now we're good to go to start consuming
that and adding that to the project there.
In this video, we've seen how you can increase
your productivity using the Navigate To
feature and Visual Studio for Mac.
Specifically, we've talked about how you can search through files,
types, members commands and more.
I'm Sayed Hashimi, keep an eye out for
any future videos in
this Visual Studio for Mac tips and tricks series.
Thank you, have a nice day.
[MUSIC]
Không có nhận xét nào:
Đăng nhận xét