WEBVTT

00:00:05.276 --> 00:00:07.250
Hi everyone, I'm Kasey Uhlenhuth.

00:00:07.250 --> 00:00:11.530
I'm a Program Manager on the .NET
in Visual Studio team at Microsoft.

00:00:11.530 --> 00:00:12.774
In today's demo,

00:00:12.774 --> 00:00:17.138
we're gonna talk about .NET
Tooling in Visual Studio 2017.

00:00:17.138 --> 00:00:22.104
Visual Studio 2017 introduces a ton
of new cool productivity features.

00:00:22.104 --> 00:00:26.269
These cover areas in debugging,
live code analysis,

00:00:26.269 --> 00:00:30.984
better navigation, IntelliSense,
and live unit testing.

00:00:30.984 --> 00:00:32.150
But that's enough slides.

00:00:32.150 --> 00:00:33.300
Let's jump into the code.

00:00:34.600 --> 00:00:39.064
Let's look at some cool productivity
improvements inside Visual Studio

00:00:39.064 --> 00:00:39.786
2017.

00:00:39.786 --> 00:00:43.072
Here I have a simple class library
that is helping me organize my

00:00:43.072 --> 00:00:45.818
different bike training workouts.

00:00:45.818 --> 00:00:48.800
The first thing you might
recognize is there's

00:00:48.800 --> 00:00:52.870
tons of different icons over
here on the left-hand side.

00:00:52.870 --> 00:00:57.530
These are part of a new feature
in Visual Studio 2017 Enterprise

00:00:57.530 --> 00:01:00.060
called Live Unit Testing.

00:01:00.060 --> 00:01:04.200
Live Unit Testing continually runs
and displays unit test results and

00:01:04.200 --> 00:01:06.920
code coverage inside the editor.

00:01:06.920 --> 00:01:08.430
It automatically finds and

00:01:08.430 --> 00:01:11.400
runs impacted tests for
every edit you make.

00:01:12.700 --> 00:01:17.880
Red xs indicate lines of code that
have failing test that hit them.

00:01:17.880 --> 00:01:21.740
Green checks indicate lines of
code where all tests are passing.

00:01:23.140 --> 00:01:26.310
And blue minus signs
indicate lines of code

00:01:26.310 --> 00:01:28.590
that have no test coverage at all.

00:01:30.510 --> 00:01:33.460
Let's look at this
failing line of code.

00:01:33.460 --> 00:01:36.420
If I click on this, I can now see

00:01:36.420 --> 00:01:40.720
all tests that are hitting this
line and all ones that are failing.

00:01:40.720 --> 00:01:45.500
I can navigate to these failing
tests by simply Double-clicking.

00:01:45.500 --> 00:01:48.110
Now I can see that I'm
at my failing test.

00:01:49.980 --> 00:01:52.687
I'm not really sure why
this is failing, so

00:01:52.687 --> 00:01:55.477
I'm actually just going
to debug this test.

00:02:01.901 --> 00:02:03.084
I can see here,

00:02:03.084 --> 00:02:07.557
that now that this test has
actually caused an exception.

00:02:07.557 --> 00:02:08.811
And if I look closely,

00:02:08.811 --> 00:02:12.640
I can see that this test actually
throws a null reference exception.

00:02:13.990 --> 00:02:18.141
I wanna draw your attention here to
the new exception helper that we've

00:02:18.141 --> 00:02:20.500
introduced in Visual Studio 2017.

00:02:20.500 --> 00:02:25.378
What you can see here is actually
that now we put the most important

00:02:25.378 --> 00:02:27.760
information at the top level.

00:02:27.760 --> 00:02:32.560
So for example, we actually tell you
what variable is going to be null.

00:02:32.560 --> 00:02:36.049
In other cases where you have an
InnerException, we're actually going

00:02:36.049 --> 00:02:39.320
to display all the InnerException
details at the top level as well.

00:02:41.430 --> 00:02:43.160
So let's investigate this further.

00:02:45.000 --> 00:02:47.942
I can see that I have two
constructors here and

00:02:47.942 --> 00:02:49.810
only one of them is failing.

00:02:49.810 --> 00:02:53.689
And if I look closely, I can see
that I have this workOuts field that

00:02:53.689 --> 00:02:57.500
I haven't actually initialized
in this constructor.

00:02:57.500 --> 00:03:00.310
So let me try just copying and
putting this in.

00:03:01.830 --> 00:03:05.030
Now the real benefit of
Live Unit Testing is that I can make

00:03:05.030 --> 00:03:08.330
these code changes and
then it's going to actively

00:03:08.330 --> 00:03:12.480
find what tests are impacted by
this change and run them for me.

00:03:12.480 --> 00:03:16.350
So I don't have to do any
of this manually myself.

00:03:16.350 --> 00:03:18.250
So you can see here now,

00:03:18.250 --> 00:03:23.000
that this test that is hitting this
default constructor is now passing.

00:03:24.460 --> 00:03:27.600
If I click on this,
I can now navigate back and

00:03:27.600 --> 00:03:31.910
see that sure enough this test
method is passing everywhere.

00:03:34.524 --> 00:03:38.384
Something you may have noticed
inside this method is a grey

00:03:38.384 --> 00:03:39.341
dotted line.

00:03:40.740 --> 00:03:42.780
And you might be wondering,
what is this?

00:03:42.780 --> 00:03:47.354
This is part of something new that
we've introduced in live code

00:03:47.354 --> 00:03:50.072
analysis in Visual Studio 2017.

00:03:50.072 --> 00:03:53.181
These grey dots indicate
a suggestion inside

00:03:53.181 --> 00:03:58.087
the editor which is a less obtrusive
way of indicating a best practice or

00:03:58.087 --> 00:04:00.559
a possible stylistic preference.

00:04:00.559 --> 00:04:04.181
Before, you would actually have
to make these into errors or

00:04:04.181 --> 00:04:07.460
warnings to have this visual
queue inside the editor.

00:04:09.250 --> 00:04:12.742
Now though, I can actually
hover over these grey dots and

00:04:12.742 --> 00:04:16.984
I can press Ctrl+dot to see what
suggestion is available to me here.

00:04:16.984 --> 00:04:20.157
If I look closely, I can see that
this is telling me that I can

00:04:20.157 --> 00:04:21.695
use an object initializer.

00:04:21.695 --> 00:04:26.793
And I can press Enter to
now apply this code fix.

00:04:26.793 --> 00:04:28.979
Going back to my Trainer file,

00:04:28.979 --> 00:04:33.740
I can actually see more spots
that have these grey dots.

00:04:33.740 --> 00:04:35.750
For example, if I I look here and

00:04:35.750 --> 00:04:39.548
I press Ctrl+dot, what I can see
here is that this code fix is

00:04:39.548 --> 00:04:42.769
suggesting I use var instead
of the explicit type.

00:04:44.188 --> 00:04:49.136
This is actually part of a new
feature in Visual Studio 2017 where

00:04:49.136 --> 00:04:55.350
we now allow code configuration and
code enforcement inside the editor.

00:04:55.350 --> 00:04:58.090
Again, I can press Enter
to apply this fix.

00:04:59.410 --> 00:05:02.750
If I wanna investigate code
style options further,

00:05:02.750 --> 00:05:06.030
I can go inside Tools > Options and
type code style.

00:05:07.350 --> 00:05:11.315
And see that for
var preferences, I chose for

00:05:11.315 --> 00:05:16.320
built-in types to prefer var at
the suggestion severity level.

00:05:17.460 --> 00:05:19.980
I can change how I want
this enforced in the editor

00:05:19.980 --> 00:05:24.260
simply by clicking on this drop down
and changing how I want it enforced.

00:05:24.260 --> 00:05:27.360
If I'm a real stickler for
code style, I can enforce this

00:05:27.360 --> 00:05:32.060
as an error so that my code will
not build if I violate this rule.

00:05:33.330 --> 00:05:34.960
That seems a little intense for
now, so

00:05:34.960 --> 00:05:36.870
I'm just going to keep
it as a suggestion.

00:05:37.970 --> 00:05:40.900
In Visual Studio, we are always
adding code actions and

00:05:40.900 --> 00:05:43.500
refactorings to make
developers more productive.

00:05:45.770 --> 00:05:49.500
So let's find other places where I
can refactor and fix up my code.

00:05:51.780 --> 00:05:56.010
If I scroll down here,
I can actually see that

00:05:56.010 --> 00:06:00.830
in this method I have a bunch of
if statements without any braces.

00:06:00.830 --> 00:06:04.960
And my team really, really,
really strongly suggest

00:06:04.960 --> 00:06:07.740
that you use braces around
all of your if statements.

00:06:09.650 --> 00:06:12.900
So instead of having to manually
add braces, we've added

00:06:12.900 --> 00:06:17.010
tons of little small code actions
to help you along the way.

00:06:17.010 --> 00:06:21.650
So for example, if I put my cursor
in this line, I can now press Ctrl+.

00:06:21.650 --> 00:06:25.380
And you can see that there is the
option to add braces here for me.

00:06:26.490 --> 00:06:31.205
And if I navigate over, I can see
that I can actually add braces

00:06:31.205 --> 00:06:35.303
everywhere in my document,
project, or solution.

00:06:35.303 --> 00:06:39.266
So if I wanna fix this everywhere in
my document, because I don't wanna

00:06:39.266 --> 00:06:42.107
find everywhere where an if
statement is written,

00:06:42.107 --> 00:06:44.980
I can just press Enter and
apply my change.

00:06:44.980 --> 00:06:48.830
And voila, you can see that it
added braces everywhere in my code.

00:06:50.550 --> 00:06:53.760
Another benefit of
Live Unit Testing by the way,

00:06:53.760 --> 00:06:57.220
is that as I make any refactoring or
code change,

00:06:57.220 --> 00:07:01.240
I can instantly see that it
didn't negatively impact my code.

00:07:01.240 --> 00:07:04.130
So I could see,
despite putting all these braces in,

00:07:04.130 --> 00:07:06.766
the refactoring was
successful because all of my

00:07:06.766 --> 00:07:09.544
unit tests are still running
that hit these lines.

00:07:12.478 --> 00:07:16.580
Another thing that we can see
in Visual Studio is improved

00:07:16.580 --> 00:07:18.730
IntelliSense.

00:07:18.730 --> 00:07:22.450
So let's go to this method and I
decide that when I save my workout I

00:07:22.450 --> 00:07:24.860
actually want to log
its intensity as well.

00:07:26.010 --> 00:07:30.380
So now when I come down to this part
where I'm logging the actual data,

00:07:30.380 --> 00:07:34.830
I know that I have some method
somewhere that has to do with

00:07:34.830 --> 00:07:35.890
intensity.

00:07:35.890 --> 00:07:37.840
So as I start typing,

00:07:37.840 --> 00:07:42.910
I can now rely on IntelliSense to
find the method that I want for me.

00:07:42.910 --> 00:07:45.000
Something new in Visual Studio 2017,

00:07:45.000 --> 00:07:49.660
you'll notice is this
bottom icon tray.

00:07:49.660 --> 00:07:53.150
And what this allows you to do
is actually filter IntelliSense

00:07:53.150 --> 00:07:54.180
by category.

00:07:54.180 --> 00:07:57.300
So you can see I can filter my
completion list to only have locals

00:07:57.300 --> 00:07:58.540
and parameters.

00:07:58.540 --> 00:08:04.415
Or only have properties, fields,
methods, interfaces, etc.

00:08:04.415 --> 00:08:08.038
And there's a very intuitive
keyboard shortcut associated

00:08:08.038 --> 00:08:09.180
with all of these.

00:08:10.400 --> 00:08:13.884
So I know that I only wanna look at
methods, so I can filter by methods.

00:08:13.884 --> 00:08:17.883
And sure enough I can see that
GetWorkoutIntensity is probably

00:08:17.883 --> 00:08:19.699
the method that I want here.

00:08:21.460 --> 00:08:24.905
You can also notice that we
added IntelliSense highlighting,

00:08:24.905 --> 00:08:28.805
where we actually bold the search
term inside your completion list, so

00:08:28.805 --> 00:08:31.091
you know why things
are suggested to you.

00:08:32.893 --> 00:08:36.487
So I'm going to add this, I'm going
to put in my workout parameter.

00:08:36.487 --> 00:08:39.568
And voila,
I have now updated this method to

00:08:39.568 --> 00:08:42.910
include the intensity
when I save my workouts.

00:08:44.450 --> 00:08:47.240
That default constructor that
we were working on earlier,

00:08:47.240 --> 00:08:50.510
has been on my mind and I haven't
really forgotten about it yet.

00:08:50.510 --> 00:08:53.960
So something that I can do
to navigate back to it,

00:08:53.960 --> 00:08:58.618
is I can press Ctrl+T or
what is called go to all.

00:08:58.618 --> 00:09:00.020
By pressing Ctrl+T,

00:09:00.020 --> 00:09:05.450
I can now navigate to any file,
type, member, or symbol declaration.

00:09:05.450 --> 00:09:09.850
So for example, I know it was
a constructor for Trainer, and so

00:09:09.850 --> 00:09:11.630
I can type this in.

00:09:11.630 --> 00:09:17.230
You'll also notice that this is a
list of all the files, types, member

00:09:17.230 --> 00:09:21.840
symbols that I can actually filter
these down by category as well.

00:09:21.840 --> 00:09:25.080
So if I only wanna see files,
I can press this icon.

00:09:25.080 --> 00:09:28.290
If I only wanna see types,
I can press this icon.

00:09:28.290 --> 00:09:30.980
If I only wanna see symbols, etc.

00:09:30.980 --> 00:09:35.732
I can also change the scope of my
search to the current document or

00:09:35.732 --> 00:09:37.230
to external items.

00:09:38.930 --> 00:09:43.710
So I know here that I actually want
to navigate to the type Trainer and

00:09:43.710 --> 00:09:45.310
I can automatically put this here.

00:09:47.330 --> 00:09:48.130
So now that I'm here,

00:09:48.130 --> 00:09:52.570
I actually wanna see how often
this constructor is used.

00:09:52.570 --> 00:09:56.140
So I can see that I have
the default constructor and

00:09:56.140 --> 00:09:58.210
a constructor that takes in a goal.

00:09:58.210 --> 00:10:00.650
I wanna know how they're used.

00:10:00.650 --> 00:10:04.690
So I can come up to my type and
I can press Find All References.

00:10:07.499 --> 00:10:09.590
Whoa, what has happened here?

00:10:09.590 --> 00:10:13.510
This does not look like the final
references we're all used to.

00:10:13.510 --> 00:10:17.708
No longer is final references
a simple, flat list.

00:10:17.708 --> 00:10:21.828
In Visual Studio 2017, we've
actually now colorized all your

00:10:21.828 --> 00:10:25.080
results inside final references and
we've made it so

00:10:25.080 --> 00:10:29.400
you can customize the hierarchy
of displayed results.

00:10:29.400 --> 00:10:33.730
So for example, here I have
the project and then the definition.

00:10:33.730 --> 00:10:35.890
I can change this to be
the Definition Only.

00:10:36.920 --> 00:10:38.890
I can change this to
be the Definition and

00:10:38.890 --> 00:10:41.300
then the Project, etc.

00:10:41.300 --> 00:10:44.544
I can even make it custom if
I want by Right-clicking and

00:10:44.544 --> 00:10:46.415
changing the grouping myself.

00:10:49.111 --> 00:10:52.815
I wanna keep it as
the Project then Definition.

00:10:52.815 --> 00:10:58.275
By doing this, I can see
that my default constructor

00:10:58.275 --> 00:11:03.486
is only ever referenced
once in my Trainer file and

00:11:03.486 --> 00:11:06.851
only once again in my test file.

00:11:06.851 --> 00:11:11.362
So I'm actually going to think about
just deleting this thing because

00:11:11.362 --> 00:11:14.733
it's only ever used once so
I don't really need it.

00:11:14.733 --> 00:11:18.000
So again, I can just verify this
directly on this by doing final

00:11:18.000 --> 00:11:21.530
references and seeing again,
that it's only in these two places.

00:11:22.600 --> 00:11:26.255
So I'm actually just
going to delete this.

00:11:26.255 --> 00:11:29.604
And now I can just go
back to my test class and

00:11:29.604 --> 00:11:32.779
change it to use
the other constructor.

00:11:32.779 --> 00:11:33.529
And again,

00:11:33.529 --> 00:11:37.279
Live Unit Testing is going to
be running in the background to

00:11:37.279 --> 00:11:41.706
verify that I did not break anything
when I deleted this constructor.

00:11:41.706 --> 00:11:44.940
And sure enough, all my tests
are still passing despite me

00:11:44.940 --> 00:11:48.050
deleting this and so
now I know that I safely deleted it.

00:11:49.700 --> 00:11:52.600
Hopefully, you're as excited with
these new productivity enhancements

00:11:52.600 --> 00:11:53.900
as we are.

00:11:53.900 --> 00:11:57.241
Don't forget to download
Visual Studio 2017 today.

00:11:57.241 --> 00:12:01.017
Also, make sure you check out some
more cool videos on Channel 9 and

00:12:01.017 --> 00:12:04.611
continue your education at
Microsoft Virtual Academy online.

