Showing posts with label video. Show all posts
Showing posts with label video. Show all posts

Wednesday, February 4, 2026

Conditional Breakpoints [4 of 5] Beginner’s Series to Visual Studio Tooling for Unity Developers

>> [MUSIC] My name is
Charles. In this video,
I'm going to show you how to
use conditional breakpoints
to focus on the data and
values that actually matter.
That way, you can debug
smarter and fix bugs faster.
More often than not, your games
most crucial features are
the ones that present the
biggest debugging challenges.
Take this project, for example.
Spawning is one of its key mechanics
and I've tried to
improve that by writing
code that changes the SpawnRate in
response to the player's skill level.
The idea is that enemy
should spawn faster
when the player is doing well
and slower when the
player is lagging behind.
To achieve this, my logic
modifies an animation curve
that represents enemy
SpawnRate over time.
Here, the x-axis represents time
and the y-axis represents SpawnRate.
This graph represents a
linear progression in
which enemies will spawn
faster as time progresses.
However, that's just a
static, hard-coded example.
In reality, our graph will
fluctuate as the player plays
and there's no telling what it will
actually look like at runtime.
If it's working as expected,
the players should be
met with a challenging
yet manageable flow of enemies.
However, somehow I've
introduced a bug that causes
the SpawnRate animation
curve to fall below zero,
which results in a ton of
enemies being spawned.
That's no fun for the player
and especially no fun for me,
the developer who now
has to figure out
what in the world has gone wrong.
Looking at the code
that's responsible
for updating the animation curve,
we can see that it uses
an algorithm that applies
some modifiers to a
configurable base SpawnRate.
The key modifier here is
the difficulty modifier,
which is used to increase the
time in-between each spawn.
This is really good
information to work with,
but I'm not really sure where
to begin my debugging process.
The problem is that algorithms
are not my strong point
and I have no idea
what could be causing
the SpawnRate to spin so
wildly out of control.
I'll need to do some debugging.
Now, the standard approach is
to use debug.log statements
to get more information
about what's happening.
However, in this case,
we've got a lot of noises,
there's just too much
happening in the scene.
We could add some logic
to make our logging a
little more intelligent,
but then we just have a
bunch of debug code peppered
throughout our logic
and no one wants to maintain that.
Instead, we're going
to use a feature of
the Visual Studio
debugger that'll help us
quickly get more information
without all of this extra code.
Let's start by adding
a normal breakpoint on
the line right after
SpawnRate gets assigned.
Then let's attach
Visual Studio to Unity.
Perfect.
Now, switch back to
Unity and hit "Play".
This will cause the debugger
to immediately cause
the execution of our code on our
breakpoint just as expected.
Now that's helpful
because as we've covered
in our other videos about debugging,
we'll be able to inspect any
and all variables that
are currently in SQL.
But I'm not really interested in
inspecting those variables just yet.
At this point in our games lifecycle,
SpawnRate is being set
to a reasonable value,
it's working exactly
as I expect it to.
While I could poke around,
I don't know if I'd be able to
discern anything of importance.
What I really care about
is inspecting the code
when the bug occurs and
only when the bug occurs.
That's where conditional
breakpoints come in.
Conditional breakpoints
are a feature of
the Visual Studio debugger.
They allow you to pause
the execution of your code
when certain conditions
have been met.
This can give us a great deal of
additional control over
our debugging process.
Let's see it in action.
Back in Visual Studio.
Let's modify our existing
breakpoints so it pauses execution
when SpawnRate dips below
a certain threshold.
For example, a threshold that
we deemed to be unacceptable
or too dangerous for the player.
To do that, all we have to do is
right-click on the breakpoint
and then select "Conditions"
from the context menu.
This will present a breakpoint
settings block that appears
just below the line on which
the breakpoint is set.
From here, we have a couple
of options to choose from.
Let's expand the first drop down.
Our options are conditional
expression, hit count, and filter.
Conditional expressions represent
any logical condition
that you can think of,
so long as the values you
reference are in scope.
When using conditional expressions,
the breakpoint will be
triggered when your expression
has been satisfied or when
a value has been changed.
For example, I can
reference SpawnRate so that
execution pauses whenever
its value changes.
Hit count triggers your
break point whenever
the line has been executed
a certain amount of times.
This is great for loops that you
suspect have gotten out of control
and are iterating more
times than they should.
Finally, the filter option
triggers your break point
when specific low-level
conditions have been met.
There are a number of
predefined filters available,
such as machine name, process ID,
and thread name that
you can use to restrict
your breakpoints to select
devices, processes, or threads.
In our case, we don't need
anything complicated.
We'll just use a
conditional expression.
Since something is
causing the spawner
to spawn enemies way too quickly,
I suspect that SpawnRate is being
set to a ridiculously small number.
Let's confirm that suspicion by
adding a condition that triggers
the breakpoint when the value
of SpawnRate drops below 0.5,
then we can examine the other values
and try to determine what's going on.
This condition is possible
because SpawnRate
is in the same scope
as the breakpoint.
You may recall from
our debugging basics
video that you should
take care to add
breakpoints to the lines
of code for all of
the variables you want to
inspect are accessible.
In our case, SpawnRate is
a variable that's local
to the function where our
breakpoint is currently placed.
So we're good to go.
Let's play the scene until
our breakpoint is triggered.
[MUSIC].
Great. Our conditional
breakpoint worked.
The execution of our code
is pause at the point
where SpawnRate has reached
an unexpected value.
Now we can figure
out what's going on.
Again, I'm terrible with algorithms.
Hopefully, the solution
will be simple.
Let's analyze each variable
that's used in our dynamic
SpawnRate algorithm.
Base SpawnRate is a field that
can be set in the inspector.
It represents the base
SpawnRate of the spawner.
It should be set to a moderate value,
which it looks like it is.
Next, spawn enemies is an instance of
a scriptable object that
holds a list of game objects.
Here we're adding the count
to the base SpawnRate
in order to increase the
time between each spawn.
That way, the game becomes easier
when there are more
enemies in the scene.
Moving on, difficulty
modifier is another field
that can be set in the inspector.
Its job is to tune down the impact
that enemy count has
on the base SpawnRate.
The lower the value, the
harder the difficulty.
In this case, it looks
like it's way too low.
In fact, a negative value should
not be allowed here at all.
This is a common problem that happens
when you expose
properties in the editor,
especially when those properties have
an effect on your
games key algorithms.
Users will always
find a way to provide
values that fundamentally
break your logic.
That being said, being able to
parameterize your component
is extremely important
because you want to be able
to hand off tasks like
tuning difficulty to game
designers wherever possible.
Instead of restricting this
property to fix the bug,
we're going to make a
couple of quick changes
to guard against bad user input.
The first is the range attribute.
Range is a Unity specific
attribute that limits
the value of a property in the
editor to a predefined range.
Let's limit difficulty modifier
to a value between 0.1 and 1.
Perfect. Now, our game designer
won't be able to input
a game breaking value.
That's a great start, but we
still need one more check.
A dynamic SpawnRate algorithm
partially depends on elapsed time.
That means that given enough time,
SpawnRate will eventually dip
down into an unacceptable range.
Luckily for us, the
solution is as simple as
clamping SpawnRate between
two acceptable values.
This will allow us to provide
minimum and maximum values.
That's it, our game
is back to normal.
More importantly, we've limited
the ability for our game designer
or anyone else who modifies
the spawner component
to break our logic.
It was all thanks to
conditional breakpoints
in the Visual Studio debugger.
Without them, we either have to sift
through tons of log statements
or manually pause and continue
the execution of our code until
we reach the broken state.
Conditional breakpoints gave
us the ability to place
a breakpoint that pause
only when we needed it to,
which helps us close
our feedback loop
and dramatically speed up
our debugging workflow.
Best of all, it works the same way
across all Visual Studio products.
Whether you're using Visual Studio
for Mac or Visual Studio code,
be sure to take advantage of these
powerful time-saving features.
[MUSIC]

Convert VS Code themes to Visual Studio

in this video we're going to convert a
vs code color theme to visual studio in
a few easy
steps we start in vs code by making sure
that the theme we want to export is also
the one that's
active then using the command pallet
we're going to invoke the command for
generating a color theme from the
current
settings that will generate a huge Json
file with all the color Tok tokens from
the theme so all we have to do now is to
save it on
disk back in Visual Studio 20122 we're
going to create a new extension project
I'm going to search for V6 and select
the empty V6 project
template let's call this project my
theme in the project I can now add an
existing item and in the dialogue select
to show all files so we can see the new
Json C file that we exported from vs
code
that brings it into my project and I can
now right click and say convert to
visual studio
theme it will produce a code behind file
a package St this is the visual studio
theme file format and all I have to do
now is to register it with the V6
manifest so I'm going to open that file
and click the assets Tab and select a
new vs package then point to a file on
the file system and notice how it
already suggest the package that file
that was generated for
me I can now test by hitting F5 to open
a new instance of Visual
Studio when I go to the tools menu I
should be able to see my new theme show
up and clicking that will select it and
show it right
here this works for any vs code color
theme all you have to do is to install
the vs code theme converter extension
into Visual Studio that enables the
conversion of the Json C color theme
file into the package def
file this is what makes it all so easy
you can get that extension for free at
the visual studio Marketplace

Cool features in Visual Studio 2022

Hello everybody and welcome to this video where I 
want to go through some of my favorite things in  
Visual Studio 2022. My name is Mads Kristensen and 
I work on Visual Studio and I have for the past 12  
years and I just want to share some of my favorite 
things, because I think that there's something  
here that you might not be aware of that will make 
you more productive and more happy as a developer  
I want to go through a bunch of new features 
some updates some tweaks to existing features  
that kind of just makes it all feel a lot 
better to be a developer when we're using 
Visual Studio. But before we dive in where I 
want to begin is with the new kind of reality  
in the way we work right. A lot of people have 
gone back to the offices but a lot of people  
have not and then there are people that are 
sometimes in the office and sometimes at home  
And when we have environments like this 
we tend to move between different screen  
resolutions and different monitor setups. 
So, for instance even though when I'm at  
home sometimes I take my laptop out of the 
docking station here and I sit in the couch  
and I do a little work from there. In that 
situation, I just have a small little screen  
but when I'm up at my desk like I am here 
I have a one of these ultra-wide monitors,  
so that's a completely different layout right 
and when I go to the office I will I might  
have multi-monitors and, so I want to make sure 
that no matter where I am where I'm plugged in  
what screen setup I've got Visual Studio is 
always in an optimal condition to allow me  
to do my best work and so let's take a look at 
some of the cool things that we can do with that  
So, here I have visual studio and you know and 
I have my various different windows like the  
Toolbox and I have the Solution Explorer out on 
the right side here and this works well for this  
particular monitor with this resolution that 
I'm using right now when I'm sitting with my  
laptop I want more of a kind of a minimal layout 
like this so in this situation I have a small  
screen so I don't want all these tool windows 
to show up I need that extra space to code  
and I actually also have a kind of a 
separate thing is when I work on extensions
I like my layout to be a little bit different 
so I write extensions for Visual Studio and  
when I do that, I always want like the errorless 
to be visible like you see here, and I show a third  
tool window over here by the Solution Explorer  
but that's only relevant for when I do that 
if I work with websites I might have other  
requirements different tool windows like the 
Task Runner Explorer or other things that I  
want to have shown that I otherwise don't 
need and then when I'm at my ultra-wide  
I really like to spread out horizontally over 
that big area and so it will look something  
like this now this doesn't look very good 
on this monitor and this screen resolution  
that I'm using right here but maybe you can get 
the idea how I can like spread out horizontally
Let's go back here so let's say you have dual 
monitors you could actually take the different  
tool windows in Visual Studio and spread 
out on these various different monitors  
so I don't have that here for this 
video so we'll have to pretend  
So, let's open a window here. A 
tool window - the Test Explorer  
and let's imagine that I take this and I drag 
that onto my secondary monitor okay and maybe  
I'll make it full screen or make it really 
big so I can easily see all my unit tests
All I have to do to save that windows layout 
so I can easily come back and forth to it  
is to go to window it's a save window layout and 
then we give it a name let's call it "testing"  
and that's it so now I saved this layout 
if I go back up to window you can see that  
I have all of my saved window layouts 
right here and I can apply any of them  
For instance, we can go to this one and 
then back to the one we just created  
"Testing". And I can do that with keyboard 
shortcuts to make that very very easy and fast  
So, this is super helpful I use this every day all 
the time as I move between different development  
scenarios but also different monitor setups so I 
can't recommend this high enough go check that out  
it was a feature we were introducing 
in Visual Studio 2019 and we've been  
improving it uh as time has gone by so 
super life saver for this new world a new  
situation with dual monitors and oh sorry 
multi-monitors for different locations
All right, so here's another thing. I have my 
code base here I got a bunch of files open  
but I can't really see how many how many 
files do I have open and it you know I don't  
really know I can only see what whatever my screen 
resolution allows me to see how wide the screen is  
and that's why we always have had this 
little thing up here you can click next to the  
the tabs and if you click that, now notice how 
you can see the list of open files  
There are some that are grayed out and italics.
Those are the ones that are not visible right now  
And then we have the ones that just look 
kind of normal. Those are the ones you see  
on the screen. And the one in bold 
is the one that's currently active  
So, that makes it really easy for me to get a 
picture of what's open and where can I find things  
But you know, sometimes I kind of just want to see 
everything all the time all the open documents  
So, if I go to the settings icon I can 
now click "Show tabs in multiple rows" 
and what's really nice here is that if you have 
the screen real-estate - if you have the vertical  
space, you can now stack all these tabs so you 
can see everything that's open. Very very handy
But there are some monitors that are you know 
have you know that are extra wide for instance  
and in those it would be kind 
of nice if we can take our  
tabs and instead of having them on top then 
move them to the side where we have more space  
So again, go into the settings and 
click on "Place tabs on the left"
So, it's really nice I can resize 
this to whatever. I want to make it fit exactly  
my monitor here right so what I'm doing here is 
I'm getting that extra vertical space. I can now  
see maybe a couple lines more of code in the 
editor because I moved the tabs to the side
But let's see what else we can do here because I 
have all these open documents and you can see by  
default, it's actually kind of nice they are sorted 
by the project they belong to, so my solution has  
multiple projects and they're all listed under 
each of those projects. That's very nice I don't  
have to sort that or, sorry, group by project. I 
don't have to do any grouping at all, but I really  
like that so now it's just alphabetically sorted. 
But I want it to be group by project like here
And if we
take it one step further here what if 
we colorize these documents per project  
So, now each tab has the same color if 
it belongs to the same project and that  
makes it even easier for me to kind of 
at a glance see where these files belong  
If we don't want it per project because 
I already group my tabs for project here  
Instead, we could do it by file extension so 
that's also very handy, so I can see all my Razor  
files, all my C# files, all my JavaScript 
files. They all have a separate color so  
it makes it easier for me to get that overview and 
that might be exactly what you'd like to do here  
And as a new thing we can also go in and 
say, let's do it by regular expression and  
let's configure the regular expressions. So, it's 
a file here that opens up and I can start typing  
I'm just going to copy that line up 
from above and let's say we want to do  
CSS and as soon as I save the file we can see 
the CSS file has now got updated with a color  
we have Razor I want to have something specific 
here and we can even take it further we can say  
you know everything that contains the 
word um you know category let's say  
so like something like this foreign so not all 
everything that has the word or c-a-t-e-g will  
be colorized so you can do that by folder 
you can do that by file name and all these  
things so you can really customize how you 
colorize these tabs it's pretty phenomenal
And, of course, if you move uh back up and use 
the tabs on the top they maintain their colors  
so that's really really nice so let's go back 
to per project I kind of like to do per project  
when I have the tabs up top and that um because in 
this case they're not grouped by a project and so  
having them colorized by project is my preference 
yours might be different but I really enjoy this
So, colors can be very very helpful to us when 
it helps us kind of identify the different files  
and so on but there's another thing where 
I feel a color is a big deal and it has  
to do with us sitting in Visual Studio using 
visual studio for you know eight hours a day  
10 hours a day sometimes five days a week 
right. This is this is home away from home  
and just like you do with your regular home you 
want to have a certain furniture you put in your  
house right you have uh what colors do you want 
your walls and so on you want to make it yours you  
want to make it feel like a place where you're 
comfortable and visual studio is no different  
so what's really cool now in in Visual Studio 
2022 is that we have made it such that you can  
take any visuals any Visual Studio Code, VS Code 
color theme and convert that to a Visual Studio  
color theme very easily and there's a bunch of 
these available out on the extension Marketplace  
and I want to just show you a few right here so go 
to tools theme and you can choose from any of the  
themes that you've got installed of course you 
get some out of the box with Visual Studio you  
can choose from and you can always go 
and say click for get more themes and  
that will get you to the Marketplace where 
you can install all these different themes  
and they're fantastic there's so many great 
ones in here and they really help us if we  
want a nice dark theme if we're sitting in a 
dark room for instance and we can even have  
Visual Studio changed the theme automatically 
when Windows changes its theme there is this  
thing here called use system setting and when we 
do that if Windows is running in a dark theme at  
night for instance after sunset Visual Studio 
will automatically switch to the dark theme at  
that point in time and back to the light theme at 
Sunrise if that's your Windows settings right so  
that's really really cool so a whole lot of colors 
that makes our lives better in Visual Studio 2022
but let's change that back 
to the blue theme for now
and I'm gonna change to a different  
project here so here's a just a very simple 
.NET console app and I want to show you some  
cool things and improvements we've done to the 
AI-based coding assistant in in Visual Studio
so I'm gonna type a new line here oh  
and notice how Visual Studio automatically 
will suggest that I put in a last name which is  
exactly what I want in this case I want the last 
name property to be inserted for me right here  
I also want the full name so let's hit 
enter again and this time it suggests age  
which is could be could be the accurate one but 
I want full name so I'm just going to pretend  
it's not showing me anything and just start 
typing public string full name and notice here  
I can just hit tab and I get my full name and 
it understands that full name is a product of  
first name and last name this is really really 
fantastic so the AI engine here in Visual Studio  
understands the context I'm in it understands 
that I'm right under the first name property  
chances are that I might want another property is 
relatively big and based on the name it also then  
first name it then also suggests hey the last 
name is usually what other people will add when  
they you know as the next logical property but 
what I was really impressed by was the full name  
that it understands what a full name is right 
it understands that when people have a first  
name and a last name and they need a full name 
this is what they want absolutely fantastic here
Let's scroll down and you can see here 
I have a method here called remove data  
and all it does it removes some data from 
the list that I have defined above it  
so what's missing here is a method for adding 
data so again I'm going to hit enter and  
Visual Studio already knows what I'm gonna do 
here. I'm going to create an "AddData" method  
so notice that based on the name remove data you 
know it understands what remove means and add  
and so it suggests that I created a method 
called "Add" but what was crazy was that it  
knew what that would do inside the method 
right so it knew that it should not take  
the list and remove something it should add to 
that list so this is just absolutely fantastic  
here I'm just coding by tapping enter and hit 
hitting the tab key here it's absolutely great  
and we can take it a step further so let's say 
that I want to create a new method or I want  
some code but I'm not entirely sure how I should 
write it what I can do is that I can express it  
in a code comment like this one so here I have 
a comment it says take the two arguments and add  
them together so the args refers to the args 
that come into the to the main method up here  
so I'm just writing here in plain English what it  
is that I would like to have 
happen and now I can hit enter
and Visual Studio will automatically 
suggest what that code might look like  
so it understands what I'm saying in English 
in the code comment and can translate that  
into something that is might be what I 
want so this is absolutely fantastic so  
this is the AI engine that is built upon a huge 
data set and using machine learning it's able to  
take the context that the AI engine is aware of 
and pair that up with the big machine learning  
model of what do people do in situations like 
this that's basically what the machine learning  
model knows and when we pair those up together 
Visual Studio can do amazing things like this
so um a big step forward for the AI 
engine here in Visual Studio 2022  
now let's call our new method here the "AddData"
"AddData" and we're just going to give it
some string what are we going to call 
it we're going to call it just one  
here and I'm gonna just duplicate the 
line Ctrl+D duplicates the line like this
and then we can I'm using an extension here called 
Shifter that lets me change integers and other  
things by keyboard shortcut here Ctrl+Alt+Up/Down 
and so now I can fill my list here with data  
now let's set a breakpoint and I'm going to 
set a specific type of breakpoint this is a  
new type of breakpoint temporary breakpoint so 
what's really nice about a temporary breakpoint  
is that it disappears as soon as the debugger 
hits the breakpoint so let's run this console up
so here it runs and it comes down here and you 
see the breakpoint is now gone right the break  
point is gone because it was temporary it only 
hits once so let's stop debugging here and um  
let's scroll up so here on line 18 I'm making 
a method call into a nougat package called  
Newtonsoft JSON and I don't really know what's 
going on inside the method called serialize object  
I might be able to find the source code 
somewhere on GitHub and then go figure it out  
but it would be really nice if there's a way for 
me to just go straight to the definition hit F12  
and go to definition so let's try that and it 
takes me straight to the source so this is not  
um disassembly or anything like that this is the 
actual source code using something called Source  
Link all NuGet packages can opt in to Source Link 
and that will allow Visual Studio to understand  
how to get to the actual source code that made 
up this particular version of this NuGet package  
and even when you're inside these files you 
can keep hitting F12 you know go definition  
until we come down here and it's a serialized 
object internal and this is a private string  
so I'm F12 and I'm going to definition 
through a file that made up the NuGet  
packets that I'm working on and I can see 
everything that's happening super helpful
all right I want to switch over to uh  
different project and I'm going to open it 
here it's the one I had opened just before  
notice how how when I open it up here all the 
files that were opened before are now open again  
and in my Solution Explorer I can see 
that all my folders and projects have  
all been expanded to the same levels that 
they were last time I used this project  
and that's all good that means that I 
can get right back into where I left off  
but very often this is not what I want very often 
I come in I open the project in the morning to  
start working on something and I don't want sort 
of yesterday's state to be expanded into Visual  
Studio I want something clean I want something 
fresh I want that fresh car smell in the morning  
right I come in I just want none of this open 
but I want to be able to open my app and work  
with it so I'm going to show you a couple 
of settings that are really really helpful  
so if you go to Tools > Options and then go to 
Projects and Solutions there are two check boxes  
that are really good to uncheck here if you're 
if you're someone like me that likes that fresh  
car smell so "Reopen documents on solution 
load" I'm going to uncheck that and "Restore  
Solution Explorer project hierarchy state on 
solution load" I'm going to uncheck that as well  
so now let's go back to the previous 
console lab here we can see that
the document was not open and the demo console 
project over here is collapsed it's not expanded  
so now let's open this project again that 
we had before I'm going to switch again  
and first of all I don't know if you notice this 
but it's instant the loading of these projects  
are now instant because no other files have to 
be opened no state had to be read from disk and  
hydrated into memory and applied on the UI thread 
in Visual Studio to expand all the tree notes  
in Solution Explorer none of that was necessary 
when you open a file let's say you open a C# file  
if it's the first time you open a C# file in 
that instance of Visual Studio that you've got  
open then it has to boot up all of Roslyn and 
everything to get IntelliSense and colorization  
and all of that working and that's called a 
language service and a language service can  
sometimes take a little while to load 
now it's not necessarily a long time  
but it's not instant like it is if we don't 
need it and we do like I do here so this is  
my default this is what I always do just a little 
performance trick if you like the fresh car smell  
come on all right I'm going to show you a 
one of my favorite new features that we are  
putting into Visual Studio this one started its 
life as a an extension and it's now coming into  
visual studio so let me let me demonstrate 
that so let's say I want to add a file to  
my project you know I can right click go down to 
add and new item and that gives me this dialogue  
but what if I go in to Tools > Options 
here and click a preview feature flag here
and what I want to search for is here enable 
quick add okay so now when I right click and  
say add new item or kick Ctrl+Shift+A is the 
same thing I get this little dialog up instead  
so I can still click on this link that's shown 
as well that says show all templates which gives  
me that experience that I'm used to but I want to 
get the simplified view we call it the quick add  
dialog and so in here I can just 
type a file name so a name .cs  
and that's what it does it just gives 
me the internal class and this actually  
respects if I have how I how my namespace 
rules are in my editor config or in my  
settings and it will do the right thing 
it uses the templates behind the scenes
but it's a little bit more clever than that so 
control shift a again for add new item to bring  
it back up let's type something a little bit 
more interesting let's what if we create two  
files what if I create a Client.cs and IClient.cs 
now let's try that I just comma separated them  
and I now have those two files but check this 
out IClient is an interface whereas Client is a  
class so the quick add method or dialog is able 
to understand that I client that pattern naming  
pattern should match an interface template and 
then give me that so that's really really handy
but I can also click create folders so 
I'm going to create a folder here called  
"folder" and you can name it whatever you want 
and just end it with a forward slash hit enter  
and now you have an empty folder I could 
also have gone in and said okay let's do  
what if I do some sub directories here 
and then end with a file - file.css
so I can create subfolders I can create 
files in those folders again I can comma  
separate these to create multiples really 
really handy to have all this working  
so this is in the preview behind a feature flag 
so you saw how I went into Tools > Options under  
Preview Features and enabled this feature so I 
can't recommend this highly enough I love this  
thing I use the extension and for years and 
I'm very happy that this is now in the box
So ,now that we have a CSS file open 
let's write some CSS. Let's do background  
let's do blue and let's do set 
index you know three four something  
all right so I'm going to show you an extension 
here called Shifter it allows me to flip between  
values in the editor really really easily let 
me demonstrate so I have a keyboard shortcut  
here Ctrl+Alt and then either the Up Arrow 
or Down Arrow and so if I'm on a number here  
like the z-index and hit up Ctrl+Alt+Up it 
increments the number like this if it was a
I say 0.08 here you see it will know to keep those 
values depending on the decimals and all this sort  
of stuff so really really handy if you just need 
to like increment by one or something like that  
but we can do more it doesn't have 
to be just numbers it could also  
be colors so here's the color blue so 
if I do Ctrl+Alt+Up I get Royal Blue,  
Dodger Blue you see here it gets lighter and 
lighter the color gets lighter and lighter  
and lighter and then it gets darker if I go down 
Dark Blue and so on so forth so I can flip through  
these very easily I can do the same if if we 
have a let's see here let's grab a color here  
with the color picker that color right there 
so if I have a hex value like this I can do  
the same and it understands what hex is and it 
knows it's a color in this case and so it will  
make the color darker or lighter as I either 
go up or down with the keyboard shortcuts
so I'm just going to write some invalid 
CSS here we can do other things like  
switch between true and 
false or you know yes and no  
or on off and so on and so forth right so so every 
time we can toggle between kind of known values  
shifter comes in and makes that super 
easy for us Ctrl+Alt+Up and down
so let me pin the upper window here let me build 
our project now notice what's going on down here  
in the output window I'm 
getting a very nice colorized  
output here because I'm using an 
extension that colorizes everything  
which is really nice something is green or gray 
means like it's fine there's no no problem but  
let's introduce a syntax error let's forget all 
right let's delete this semicolon and run again  
so now yeah we get an error in the error list 
but we also see that our output is now red  
because there was an error so it makes 
the output window really really easy to  
kind of just glance over or skim and 
you can see if you have anything red  
or anything orange if it's like a warning and 
that's just really really helpful so there's  
a bunch of these extensions out there that you 
can use the one I use is called VSColorOutput,  
VSColorOutput so go check that out 
really really handy thing to have
and the last extension I want to show you  
is compile again is one called 
Solution Colors so you may have  
the issue where you have multiple instances of 
Visual Studio open and how can you tell them  
apart they all look the same what if it's the same 
repo you have open in both but different branches  
now they look almost identical the solution 
names are the same all the all the files in  
Solution Explorer are the same how do you tell the 
difference between open instances of Visual Studio  
well what we can do with Solution Color 
is that we can right click the solution  
and set a color so I can give it any color I 
want or I can enable auto mode so auto mode  
basically takes the solution path and the branch 
name and other things and makes like a unique  
color that it will always map to that same color 
so if if I now open another Visual Studio here
we can see here it will apply a color as the 
solution is low to see this one turns blue  
you can see the blue color up here and the other 
one got the magenta color or pink right up there  
now I can go in here and go to options 
and make it a little bit more visible  
I can go and say instead of just colorizing 
up here the up there and it also puts a line  
at the bottom of the screen you know maybe I 
want a little bit extra maybe I want it on the  
let's hear let's look at the borders instead 
of just the bottom what if I wanted at the top  
as well so I'm gonna go ahead and do that 
and so now I have a thing here at the top  
this is very very cool because 
now I can very very easily see  
that this is the you know I have a 
magenta one I have a blue one and so on  
and I can even tell by hovering down in the 
taskbar those colors are also present here  
under each of the thumbnails in the
Windows task bar
and if I don't like magenta I don't 
have to have the even though we have  
auto mode is on I can always say no 
no I want you know give me a burgundy  
and I can keep that color and all all other 
solutions will still have the automatic one  
except for the ones that I manually said hey no 
no I want to specify the exact color for this  
particular solution and of course I can also hit 
the custom one and then select any color you know  
RGB color that I can find here so or that that 
exists rather so you can be really really specific  
here and it stores it um in the .vs folder at the 
solution root so it's not something you want to  
check into source control you can but it's not by 
default so this is just a personal setting to you  
having you having put colors on yours does not 
change the colors that your team members might  
have chosen for theirs or if they don't want 
any colors that doesn't make any difference  
either because they're kind of 
just local to you your machine
so this is called Solution Colors - Solution 
Colors so throughout this whole demo you  
probably didn't notice because there's no way 
to tell that I've been working inside a VM  
but not just any VM or virtual machine I've been 
working inside a Dev Box a Microsoft Dev Box and  
just you can tell there's really no way to tell 
this is just Visual Studio running you can run  
with any other app that I have installed that 
I need to have installed to make my uh make me  
able to work on the project I'm working on right 
so it's it's just another VM but it's hosted in  
the cloud and it's super powerful so if I go to 
devbox.microsoft.com this is where I have access  
to my Dev Boxes and this is where my it department 
has given me the opportunity to create new  
Dev Boxes that I can connect to so I have two here 
I got Legacy and I got Podcast those are two and  
they're pretty powerful uh eight core 32 gigs of 
RAM and a terabyte of SSD very fast SSD drives  
so depending on your workload you may want 
to have a super-fast powerful machine or  
if you wanna if you have a lighter 
workload you can go sort of smaller  
and it's very easy to create a new one so anyone 
can just come in here say hey I want to start  
on a new project I want a clean machine and you 
just set it up very very easily from this website  
so it's a very very cool technology it makes sure 
that your Windows is always up to date and the  
latest patches it's kind of a managed thing 
your IT department can manage all these Dev  
Boxes the way they can also manage your own you 
know physical workstation or laptops um to always  
keep them secure compliant up to date connect 
them back to your network have all those things
um so that you won't even notice that you're on 
a VM and the first time I tried this I was I I  
will admit I was a little bit skeptical 
but I signed in for the first time and  
OneDrive started synchronizing my files so all of 
a sudden I had all my files everything was there  
all the images and all these different things 
that I have on my Desktop and you know in the  
My Documents and whatnot it was all there and the 
image came pre-installed with Visual Studio and a  
bunch of other tools that I needed so I could just 
get to work immediately and it really didn't feel  
like it was like a a VM that was hosted in the 
cloud or anything like that it felt just like  
another one of my machines and um I'm very excited 
for this I have I have a specific specific use  
case uh which is you know Visual Studio sometimes 
can use a lot of uh resources when you compile  
all the time and run debug and all that sort 
of stuff it takes a lot of resources we want  
it to take a lot of resources right we wanted to 
compile as fast as possible we don't want to sit  
and wait so we wanted to use be able to use all 
the resources that we've got now the problem with  
that is that it for me I have a laptop and it kind 
of drains the battery so I can't use Visual Studio  
on battery on my laptop for very long but with 
Dev Box I can I can go all day long because I  
don't do any of that heavy lifting locally on 
my laptop it all takes place in the cloud with  
much beefier hardware than what I've got in my 
laptop so I get a much faster experience and I  
get battery that lasts all day it's perfect so is 
it public preview you can go ahead and try it out  
um I encourage her to do that I think it would 
be fantastic and um there's a whole admin story  
for your it admin you may want to uh talk to 
them about it as well because there's a whole  
opportunity for them to make this secure and 
compliant and all this sort of stuff making sure  
that you don't spin anything up uh that they don't 
think you should and um it's so it's a win-win  
it's a win for the developer and it's a win for it 
you really get that flexibility that productivity  
that and get all the hardware you need when you 
need it so um go check out Dev Box - Microsoft 
Dev Box and that was it for this uh 
brief video of me going through some  
of my favorite features in Visual Studio 2022 
new features are added all the time so make  
sure you go check it out uh install the latest 
version and try it out for yourself thank you

Create Your First C# Windows Forms Application using Visual Studio

hey guys in this video I'm going to show
you how you can create your first
Windows Form application since C sharp
on your Visual Studio
so let's get started and let's see how
we can do it
so when you open Visual Studio it will
look like this here we are going to
create a new project so just click on
create a new project
and then here either you can search for
Windows Form application or you can just
select these drop Doms and select C
sharp here and the platform will be
desktop so you can just select windows
for example and then you can choose the
all project type and the project type
here is desktop and from here you can
see two Windows Form app options so here
we can select this option which is
Windows Form app using.net core so just
select this option and then click on
next
on the next window you can give the name
of your project I'm going to name my
project as my first project for example
and you can see I don't like to give
spaces in the project name so if
possible just write or give a project
name without spaces right and then click
on next
and here the framework will be dot net
6.0 or whatever is the latest version of
dotnet in my case it's dotnet 6.0 click
on create
and this is going to create a Windows
Form application in c-sharp for you so
now you can see my project has been
created
you will be able to see this kind of
solution on the left hand side and on
the right hand side you can see this
form one dot CS file so this is the
program file where you will write the
program
now how you can open the designer you
can see this form one dot CS file right
and when you just expand this uh you
will be able to see C sharp form one
designer also here right so when you
double click on this form one dot CS
file it's also going to open the
designer for you so just wait for the
designer to load for this form one so
now you can see this form one dot CS
design window is open
you can resize
this form one window here you can even
give the title to it right now the title
here is form one you can change the text
of this let's say you want to change the
text to uh my app and then press enter
the title has been changed to my app
right so you can change the text for
your form by just changing the title
here you have all the other options to
change the appearance of your form or
you can even change the font size
if you are using some fonts in your form
or you can also change the behavior of
your form so you can drag and drop some
components in your form from the toolbox
so if you don't see the toolbox just
click on this toolbox option here which
is going to load all the toolbox if you
want to pin the toolbox
window you can just click on pin and to
box window will be pinned here so you
can easily drag and drop all the
components from here
so you can see
all Windows Form components you can see
buttons labels and other components
I'm going to use a button so I'm going
to just drag and drop this button into
my form I can even use the label so I
can drag and drop this label into my
form
and let me also use the text box so let
me search for
this text box and put it here okay
so I can
you can see a drag and drop all these
components here now for this label
I can change the label text
from this
properties window so the text here is
label one I can just write
enter some text for example or enter
your value because I want the user to
enter something into the text box right
so I'm going to just write enter
some
text here and then press enter and you
can see this label shows that I will
just drag this text box here also
and now
in the behavior you will be able to see
uh all these Behavior options
I want to change the anchor option here
so you can see the anchor is right now
top and left I can even
click on this option to Anchor it to the
right side so what it's going to do is
let me just
resize it according to my form
and I can even
do the same for this label but I do not
need this for the label
so what I it's going to do is when I
anchor it to the right when I resize my
window you can see the text box resizes
right
same I can do with the button also so
this button text says button one I'm
going to just change it to
click me for example
and then press enter and you can see the
button text is changed
I can even change the anchor for it so
right now it's top left I can anchor it
to the right and then I can just move it
here and
then just
resize my button
until it shows this kind of
line here right
so now
when I even resize my window it's going
to uh
just resize according to the width of my
frame right I can even anchor this
button to the bottom so that
it moves to the bottom let's see how can
we do that so I can anchor it to the
bottom and then
what happens is when I just make it
bigger this button size becomes bigger
for example right so this is how you can
change the behavior so you need to play
with all these options and see what you
can do
for example I can change the background
color from here
so here I have all these options for
changing the background color
let's say I want to just choose this one
and then you can see the background
color of my form has been changed and
the background color of my button also
has been changed
so now let's write some code so what I
want to do here is whenever some text is
entered into this text box and when I
click the button I want to open a
message box with the same text for
example right so
the main thing to note here is the name
of this text box so when I select this
text box the name of the text box is
text box one so for using this name I'm
going to use this text box text and show
the text on the message box for example
right so just copy this ah name from
here and then select your click me
button just double click on this button
which is going to
create a listener for your button right
so the button name was Button one you
can even verify that by going here and
then you can see the name of this button
you can see the name of the button is
button one and the method which is
created is button one click listener
right so let me just write some code I'm
going to create a
string variable I am going to name it as
text is equal to and I am going to take
the name of my text box right which was
text box one so I'm going to just write
Dot
text which is going to uh
give me the text whatever I write in the
text box it's going to just take the
text and assign it to the text variable
right now I want to show this text into
a message box so I can just use a
message box component just write
message box
dot show
and then
I can just write
U entered and then semicolon space and
then plus and then the text variable
which is text okay once you are done
just save your code and then you can run
your code by just clicking on this run
Icon so I'm going to run my code
and hopefully everything works fine you
can see my code is running
when I resize you can see the button and
the text box resizes according to the
size when I move down the button size is
changed right now let me enter something
so I'm going to just write
Dom here and then I'm going to click on
click me button and it says you entered
Dom right I can just write 34 here and
I'm going to just click on click me and
it says you entered 34 okay
so it is going to open this message box
every time when I click on the button
and it's going to show whatever text I
wrote here
so this is the basic Foundation of how
you can create a Windows Form
application in Visual Studio using C
sharp and create your forms and use your
forms in Windows Form application so I
hope you've enjoyed this video and I
will see you in the next video

Debugging Basics [1 of 5] Beginner’s Series to Visual Studio Tooling for Unity Developers

>> My name is Charles,
and in this video,
I'm going to show you how
to use the debugger in
Visual Studio to get a
better understanding of
what your code is doing at runtime
so you can fix bugs faster.
If you'd like to follow along,
the example project used in this
video is free for download.
Unity comes with a rich set of
features that you can use to
implement game mechanics and
create stunning visual effects.
Its physics system can simulate
almost any physical interaction,
and its visual tools like
Shader Graph and the Universal
Render Pipeline can be
used to generate an extremely
realistic or stylized
look for your game.
When coupled with its
scripting engine,
there's no limit to the variety
of things that Unity can achieve.
However, as great as
these features are,
they tend to slow down the
process of debugging your code.
Let's take this project, for example.
As you can see, it's a
relatively small game
with a few simple mechanics.
We have a third-person view
of the player and we can
perform various attacks against
the enemies that are
spawning around us,
my favorite which is this really
cool shooting mechanic where
the camera moves in over the
player character's shoulder
when her gun is drawn.
Very cool, except it has one problem.
While everything seems
to be working fine,
the console is filled with errors.
Let's pause the game
and take a closer look.
At first glance, we can
see that this error
is being caused by a Null
Reference Exception.
More specifically, if we click
on the error in the console,
we can see that this exception
is occurring somewhere in
this SendDamageMessage method
in the ParticleCollisionListener
class.
Let's go ahead and open
that up in Visual Studio.
Somehow, a variable in
this method is inadvertently
being set to null.
In programming, null
values are very bad.
They represent a void or
black hole in your code,
so we'll need to account
for that in this logic.
But we can't do that if we don't know
which variable is being set to null,
so we'll need to do some debugging.
A common approach to
debugging in Unity is to use
log statements to reveal
exactly where your code
is doing in the console.
Let's add a few calls to Debug.Log
to our broken method now.
We will place one at
the top that lets
us know when the method
is being invoked,
then another to display the value of
this variable here called Damageable,
as well as one to display
the value of Message.
Finally, one at the end
of the message to let us
know when it's completed
its execution.
Now, we can play the game
until the error appears
again and analyze the logs to
figure out what's going on.
It looks like there's
some edge case that's
causing Damageable to be set to null,
which results in our
Null Reference Exception
when the applied damage
method is invoked.
It's a good place to start,
but we still need more information,
which means we'll need to add
more log statements and
run our game again,
and even that might not be enough.
We might have to complete two
or three more iterations of
this slow trial and error approach
before we fully understand
how to fix this bug,
and that just takes too much time.
Luckily for us, Visual
Studio has a tool
that offers the perfect
solution to this problem.
The debugger in Visual Studio is
a tool that allows us to step through
our code line by line and inspect
the values of our
variables at runtime,
or in other words,
as the code is actively running.
To do that, we'll need
to make sure that
Visual Studio is attached
to the instance of Unity
that's currently running
our project by either
clicking the play button that's
labeled Attach to Unity,
or by locating the Unity
instance manually,
which we can do by expanding
the Debug menu and clicking
"Attach Unity Debugger."
Doing so will open
a small window that
contains a list of all the
available Unity instances,
including remote instances that
are running on your network.
Let's go ahead and click
on "Attach to Unity",
which is a much quicker option.
Now Visual Studio's attached to
the correct instances of Unity,
and we can start
debugging our project by
switching back to Unity
and pressing "Play".
Now we're officially
debugging our project.
But if we want to find out what's
causing our null reference exception,
we'll need to set what's called
a breakpoint in our code,
so let's stop running
our game and switch back
over to Visual Studio.
Breakpoints are a feature of
the debugger that allow you to
pause the execution of your
game on a single line of code.
Once paused, you can
examine variables,
step through the code,
and perform other
similar debugging tasks.
Let's set up a breakpoint at the top
of the SendDamageMessage function.
We can do that by clicking the
gray bar to the left of our code.
Alternatively, we can expand
the Debug menu and click the
"Toggle Breakpoint" button,
which has the keyboard shortcut F9.
Now we're ready to start debugging.
We can do this by switching back to
Unity again and pressing "Play",
or by expanding the play menu
and selecting "Attach
to Unity and Play",
which will play the
open scene and switch
the focus back to Unity
for us automatically.
Now, the key to diagnosing any
problem is to recreate the bug.
But first, it's important to
understand what the
code actually does.
We'll start with the happy path
and shoot an enemy so we can
step through the code and see
the expected behavior play out.
Now that we've shot an enemy,
we can see that the
running scene is paused,
which means that our
breakpoint has been reached.
Over in Visual Studio,
we can see that the first
line is now highlighted,
signifying that the execution
is currently paused there,
and down at the bottom of the screen,
we can also see that
the debug window is
populated with all the variables
that are currently in scope,
including the offending
Damageable variable.
Let's move the execution of
this code one step forward by
pressing the Step Over
button in the toolbar.
Now the execution has
progressed to the next line.
If we look back at the debug menu,
we can see that the
Damageable variable has
now been populated and
is no longer null.
If we set forward again,
this time I'll just
use the shortcut F10,
and one more time, it's clear that
the code is working because
the exception was not thrown.
Now we can go ahead
and recreate the error
by shooting a non-enemy in the scene.
First, let's let the code
go back to executing as
normal by pressing the "Continue"
button in the Toolbar.
Then let's switch back to Unity
and shoot this box in our scene.
Now the scene is paused,
and the Visual Studio debugger has
stopped the execution
of the first line,
so let's step through it
again, and look at that.
In this scenario, the damageable
variable is null because
the game object that was passed
into this function, the box,
did not have the component called
Damageable attached to it,
and when we set to the next line,
we can see that the
exception is thrown,
which, of course,
we'll need to handle.
Thanks to the debugger,
we were able to recreate
the bug and determine
what was causing it.
All we have to do now is add
a simple null-checking
guard clause to
the top of the
SendDamageMessage function.
Then step through the code one
last time and confirm that it works.
Let's go ahead and add our new logic.
The guard clause right after
Damageable is initialized.
If Damageable equals null, return.
Now, with our breakpoint still
in place, let's test it out.
We'll take aim at our box,
and now we can set to the code again.
But this time, our guard
clause will recognize that
Damageable is null and break
out of the function early.
We can quickly confirm this by
hovering over Damageable with
our mouse to reveal the
inline inspection tool tip.
Sure enough, Damageable is null,
so our logic will now
break out of this function
prematurely to avoid
the null reference exception
from being thrown.
Log statements are a quick way to
expose what your code is doing,
but they only offer so much.
The Visual Studio debugger,
on the other hand,
gives you access to all the
information you need to
understand how your
logic is operating,
and the setup and process is similar
across all Visual Studio products.
So whether you're
using Visual Studio,
Visual Studio for Mac,
or Visual Studio Code,
make sure you take advantage
of this powerful tool so you
can debug issues more
effectively and fix bugs faster.
[MUSIC]