[00:00:06] Hey everyone. Today we're going to talk [00:00:07] to you about CS WinRT 3.0 and how we [00:00:09] modernize in Windows SDK projections [00:00:11] that are in the .NET SDK. [00:00:14] I'm [00:00:15] and I'm a principal software engineer on [00:00:17] the Windows team [00:00:18] focused on improving the developer [00:00:19] experience on Windows including working [00:00:20] on CS WinRT. [00:00:22] >> Hey folks, I'm Sergio. I'm from the [00:00:23] store client team and I also work on [00:00:25] building CS WinRT with Mano. [00:00:28] >> So to start off, I want to start off [00:00:30] with some history. So CS WinRT was [00:00:31] initially released during the .NET 5 [00:00:33] time frame. [00:00:34] Since .NET 5, .NET has had numerous [00:00:36] releases. Once when they added trimming [00:00:38] support, then another release when they [00:00:39] went and added AOT support. [00:00:41] After each one of these releases, we [00:00:43] went and got our CS WinRT projections to [00:00:45] be trimming compatible and then AOT [00:00:47] compatible. But we did this in a way [00:00:49] such that that we didn't do any breaking [00:00:51] changes. So there were some proof gains [00:00:53] and size improvements that we were not [00:00:57] that we able to take advantage of that [00:00:58] we were not [00:00:59] in order to be backwards compatible. In [00:01:01] addition to that, over time we have been [00:01:03] collecting various feedback from folks [00:01:04] that have been using CS WinRT [00:01:07] including pain points related to our [00:01:08] trimming support and our AOT support. [00:01:10] Specifically ones that we need a [00:01:11] breaking changes to go address. So we [00:01:13] decided CS WinRT 3.0 was the right time [00:01:15] to go address all of these and go [00:01:19] get back to wins on the optimizations [00:01:20] that we were leaving on the table [00:01:22] and also move to a newer recent .NET [00:01:24] version so we could leverage everything [00:01:26] that .NET has shipped since then and [00:01:27] also leverage some of the stuff that [00:01:29] .NET went and added to address some of [00:01:31] the pain points that folks were running [00:01:32] into in these interrupt scenarios [00:01:33] related to CS WinRT. [00:01:36] >> All right, we're going to get more into [00:01:37] the details of what WinRT is and how CS [00:01:39] WinRT works later. But first we want to [00:01:41] show you the how CS WinRT 3 is actually [00:01:43] a production ready library and we're [00:01:45] already about to basically roll out to [00:01:47] production ourselves as well. So first [00:01:50] we want to share some numbers about [00:01:51] binary size which has been one of the [00:01:53] main areas that we spent so much time [00:01:55] working on and optimizing in CS WinRT 3. [00:01:58] So here we have some numbers for the [00:01:59] Microsoft [00:02:00] Um, we can see on the left we have the [00:02:02] binary size numbers for the current [00:02:04] release build, which is with CS 2.0 and [00:02:07] on .NET 10 and native AOT, uh, which is [00:02:09] about 129 megabytes. And now on the [00:02:12] right you can see the new CS [00:02:14] three build still on .NET 10 for now and [00:02:16] on native AOT. And this is about 22 [00:02:18] megabytes smaller, which is over 16% of [00:02:21] reduction. This is just from updating [00:02:23] from CS two [00:02:24] to CS three. So you can see just how [00:02:26] much just this change of library impacts [00:02:28] our binary size. And this again is a [00:02:30] production ready thing and we're [00:02:31] actually rolling it out to Windows [00:02:32] Insiders experimental users right now. [00:02:35] And then next we also have some um, [00:02:37] example like reference numbers for a [00:02:39] smaller app. In this case it's the [00:02:40] Contoso camera app which we're going to [00:02:41] demo later. Uh, in this case moving from [00:02:43] CS two to CS [00:02:46] reduce the binary size from 5.6 [00:02:48] megabytes to 5.08 which is again almost [00:02:51] 10% improvement. And with this we also [00:02:53] want to show you how the reduction in [00:02:55] binary size is actually proportional to [00:02:57] the complexity of your app. So it kind [00:02:59] of scales with it and the larger your [00:03:00] app is and the more complex it is and [00:03:02] the bigger the wins is in terms of [00:03:04] binary size as you move to CS three. [00:03:07] And then next another thing that we also [00:03:09] want to demo is um, not just [00:03:11] improvements in binary size but also in [00:03:12] IntelliSense builds. So for context [00:03:15] we're going to also cover this more [00:03:16] later. In CS [00:03:17] 2.0 we have a source generator that is [00:03:19] responsible for analyzing all of your [00:03:21] code, figuring out what marshalling code [00:03:22] we need to generate and then generate [00:03:24] stats that your code works correctly [00:03:26] when you pass for instance objects to a [00:03:27] native callers. And these are actually [00:03:29] very very expensive. So on the left you [00:03:31] can see the total CPU time that it takes [00:03:33] to build the entire store client [00:03:34] including all the dependent projects, [00:03:36] which is over 115 seconds which is like [00:03:39] a fair amount. And instead in CS we [00:03:41] completely removed all of these [00:03:42] generators and we moved to a single um, [00:03:44] native compiled interop generator which [00:03:47] runs just when you actually are ready to [00:03:48] deploy your app. And this not only takes [00:03:50] just nine seconds for a clean build [00:03:51] which is almost 13 times faster, but [00:03:53] also this is not part of the IDE loop. [00:03:55] So like it doesn't have to run as you [00:03:57] load your project into VS. So everything [00:03:59] loads up much faster in the IDE and you [00:04:01] get a more responsive Visual Studio [00:04:02] experience. And then you just pay for [00:04:04] this when you're actually press F5, you [00:04:05] know, to actually run your app. And [00:04:07] similarly for incremental builds, [00:04:09] uh the performance went from 24 seconds [00:04:12] with CS WinRT 2 to just 4 seconds in CS [00:04:14] WinRT 3, which is again almost six times [00:04:16] faster. So we hope that as you move to [00:04:18] CS WinRT 3, you're also going to [00:04:20] experience a much faster, you know, [00:04:21] intelligence experience. Now to clarify, [00:04:23] this is not we're not saying that the [00:04:25] build itself is going to be 13 times [00:04:26] faster. This is just the time to run the [00:04:28] um source generators that we have, but [00:04:31] this will also impact the build uh [00:04:32] itself. So we're also expecting that [00:04:34] builds should be a little bit faster in [00:04:35] CS WinRT CS WinRT 3 as well. [00:04:39] >> So you heard Sergey talk about some of [00:04:41] the wins for CS WinRT 3.0, but I want to [00:04:43] go back and first talk about what CS [00:04:45] WinRT is and how some of you may even be [00:04:47] using CS WinRT and the projection that [00:04:49] it generated without being aware that [00:04:51] you're actually using it. [00:04:53] So to start off, I need to start off [00:04:55] with what WinRT is. So Windows has [00:04:57] various different types of API surfaces. [00:04:59] One set of these API surfaces are WinRT [00:05:01] APIs, [00:05:02] which are types that are described in [00:05:03] WinMD files and they're meant to be [00:05:05] consumable from different languages. [00:05:07] So for instance, a certain language had [00:05:09] a projection tooling, [00:05:11] it will go read these WinMD files [00:05:13] and create a projection surface for that [00:05:15] language [00:05:16] and it will be it will be generated in a [00:05:18] way that is natural to that language and [00:05:20] will enable folks in that language to [00:05:22] call APIs [00:05:24] generated by that projection. [00:05:26] So we do the same thing for CS WinRT [00:05:28] where we go read these WinMD files and [00:05:30] we create this a C# projection for it [00:05:33] that's natural to C# developers. We [00:05:35] enable them to call these WinRT APIs [00:05:37] that are exposed by these WinMD files. [00:05:40] So how do you go about using this? So [00:05:42] today you have your target framework and [00:05:44] you'll be specifying something such as [00:05:45] net 11 and optionally you could go [00:05:48] specify a Windows OS version that you [00:05:50] want to target. So in this case, we got [00:05:51] Windows 10.0 [00:05:53] .26100.0. [00:05:55] So this tells the .NET SDK that you want [00:05:57] to [00:05:58] pull a reference to a Windows SDK [00:05:59] targeting pack. We have the CS WinRT [00:06:01] projection that we generate and you will [00:06:04] get a reference to this and then you [00:06:05] will be able to call WinRT APIs that are [00:06:07] in this projection. So in this case, we [00:06:09] got a geolocator API, which is a WinRT [00:06:11] API from the Windows devices your [00:06:13] location namespace which you're calling [00:06:16] and you're calling it to get the [00:06:17] latitude. [00:06:18] And the moment you specify this target [00:06:20] framework, you're able to call that API. [00:06:24] So in addition to consuming WinRT APIs, [00:06:26] you could actually also go write a C# [00:06:28] library [00:06:29] and make it enabled to be callable from [00:06:31] other WinRT supported languages. So for [00:06:33] instance here, so we have the CS WinRT [00:06:35] component property that you go set to [00:06:37] true [00:06:38] and once you do that, you could go write [00:06:40] your your C# library as you would write [00:06:43] any other library, but they will need to [00:06:44] be written in a WinRT compatible way. So [00:06:46] we have analyzers that will help enforce [00:06:48] that all of the classes that you write [00:06:50] and so on are WinRT compatible. So in [00:06:52] this case, we got a timer class which [00:06:54] has a tick event and a start function [00:06:56] and we are going to go analyze the whole [00:06:58] public API surface of this library [00:07:00] and go generate a WinMD file to [00:07:02] represent this library. [00:07:03] And then we are also going to go [00:07:04] generate a projection to enable other [00:07:06] languages to call into this library. [00:07:11] So I mentioned earlier that [00:07:13] we we basically generate a projection [00:07:14] such a way that will feel natural to C# [00:07:16] developers. [00:07:17] So here are some examples that [00:07:18] demonstrate this. So at the top here, we [00:07:20] have a storage file static class [00:07:23] a storage file [00:07:25] we have a storage file class that we [00:07:26] have we're calling a static function [00:07:27] from get file from path async. [00:07:30] And [00:07:31] this is an async function, so we're [00:07:32] using an await keyword [00:07:34] and so we're waiting for the we'll be [00:07:36] able to wait for the async function to [00:07:37] complete and get back the storage file [00:07:39] result. [00:07:40] And then we're able to take this file [00:07:42] and pass it to another function called [00:07:43] open async and then similar we're using [00:07:46] a wait keyword again, but this time we [00:07:48] have a ask to max extension function [00:07:50] that we export [00:07:51] that allows you to convert that back to [00:07:52] a C# stream object. [00:07:54] Then you're able to take the C# stream [00:07:55] object and pass it to other C# APIs such [00:07:58] as stream reader [00:08:00] and in this case, we're going to go read [00:08:01] an entire file and get back a string. [00:08:03] You can see another example right below [00:08:05] it where we have a folder [00:08:07] and it has a [00:08:08] API call get phone sync that we are [00:08:10] calling. And basically this is going to [00:08:13] return it in an I vector view. [00:08:16] But what we do is basically we map all [00:08:18] the collection types where possible to [00:08:21] collection types. [00:08:22] So the I vector view you will map it to [00:08:23] an I read only list so this more feels [00:08:25] more natural to C sharp developers to go [00:08:28] and this also enables you to then use [00:08:31] what you get back with other C sharp [00:08:33] functions that are expecting I read only [00:08:34] list such as the link APIs where we [00:08:36] could now go use first or default with a [00:08:38] custom lambda to filter it to a text [00:08:41] file. [00:08:41] So here we filter it to a text file and [00:08:43] we are able to get back the first entry [00:08:44] that meets that criteria. [00:08:46] And I listen to those the other things [00:08:48] that you make use of such as collection [00:08:49] expressions where we are had a title and [00:08:52] author with that we are passing as a [00:08:53] collection expression to the retrieve [00:08:55] properties async function. [00:08:56] Or you could go and use pattern matching [00:08:58] where here we we have the false list [00:09:01] and we are doing pattern matching to get [00:09:02] a summary back. [00:09:05] >> So Mano covered what [00:09:08] is at a high level and now we want to [00:09:09] move into showing you some of the pain [00:09:11] points and that we were present in [00:09:14] and how we actually improved all of [00:09:15] those scenarios in [00:09:17] so actually why did we decide to rebuild [00:09:19] itself from scratch? [00:09:21] So the first pin point that we want to [00:09:22] cover is tied to version coupling. That [00:09:24] is that using libraries that depend on [00:09:26] different version of [00:09:28] can actually result in unexpected [00:09:29] issues. Here we have an example you can [00:09:31] see imagine this is in your [00:09:35] maybe we are referencing [00:09:36] explicitly in this case we're pulling in [00:09:38] version 2.0.8 maybe because it had some [00:09:41] specific bug fix that we needed. And [00:09:43] then we also have a couple of package [00:09:44] references to a couple of control [00:09:46] libraries for instance one for charts [00:09:48] and one for controls. [00:09:49] Now those two [00:09:51] controls packages might have been [00:09:52] compiled against a different version of [00:09:55] than the one that you are explicitly [00:09:56] referencing. In this case let's imagine [00:09:58] those were compiled against [00:09:59] 2.1. If you try to build your app in [00:10:02] this situation you will get some kind of [00:10:03] confusing errors saying that oh the [00:10:06] version of the assembly that you're [00:10:07] referencing doesn't actually match [00:10:09] and you might be like I don't understand [00:10:10] what this is. I'm just trying to get my [00:10:12] app to build. [00:10:13] And so the way you have to fix this in [00:10:15] this case would be to [00:10:17] bump your CSMRTD version in your app to [00:10:19] match that. But even that is not [00:10:21] sufficient because in some cases you [00:10:22] might have the opposite situation where [00:10:24] you might have packages that could that [00:10:26] were compiled against an older version [00:10:27] of CSMRTD but you want to use a newer [00:10:29] one meaning that [00:10:30] you still wouldn't get any of those bug [00:10:32] fixes into those packages because those [00:10:34] were generated with a previous version [00:10:35] of CSMRTD. So you would have to wait for [00:10:38] all of your dependencies to actually go [00:10:40] and update with a newer version of [00:10:41] CSMRTD and then ship a new package and [00:10:43] then update your reference there and [00:10:45] then finally your app can work as [00:10:47] expected. So the whole thing was [00:10:49] had a lot of friction every single time [00:10:51] we would ship the new version of CSMRTD. [00:10:52] And so we changed this in CSMRTD 3.0. [00:10:54] Mano is going to get into more details [00:10:56] later about exactly how. But the point [00:10:58] is that in CSMRTD 3 you will no longer [00:11:00] have to wait on all of your dependencies [00:11:02] to update for every single new release [00:11:03] that we have. You can just reference the [00:11:05] latest version of CSMRTD in your app and [00:11:07] then you get all the bug fixes and all [00:11:09] the improvements at the same time [00:11:10] without having to wait and without [00:11:12] having to deal with weird assembly [00:11:14] version issues. So all of that should [00:11:15] work smoothly now. [00:11:17] Another pain point that we also want to [00:11:19] cover is related to AOT friction. So [00:11:22] CSMRTD when first was [00:11:25] introduced, Mano mentioned this earlier, [00:11:27] was back in .NET 5 which didn't have [00:11:28] trim support or AOT support. And so when [00:11:31] those came out we had to add support for [00:11:32] that after the fact. But we had to do [00:11:35] that in a way that wouldn't introduce a [00:11:36] breaking change because there could [00:11:38] still be packages out there compiled [00:11:39] against a previous version of CS of [00:11:41] CSMRTD 2 and we didn't want to break [00:11:43] those. So we got things to work but the [00:11:45] result was not really seamless for [00:11:47] developers. Here we have an example. [00:11:48] Imagine you have a custom control. In [00:11:51] this case we have a this tag button [00:11:53] that just has some you know a method [00:11:55] that combines some tags on different UI [00:11:56] elements and this will actually you [00:11:59] would expect this to just work but [00:12:00] instead you get a bunch of warnings that [00:12:02] are not really obvious. You can see one [00:12:04] on the tag button class itself, one on [00:12:06] the framework element [00:12:08] pattern matching in the switch and one [00:12:09] on the collection expression. So instead [00:12:11] of just things just working and [00:12:13] compiling fine, you get some weird [00:12:15] errors. And you can go through them, and [00:12:16] we have some code fixers for some of [00:12:18] them, and you can fix your code to get [00:12:19] things to work, which it does now as of [00:12:21] CSLA 22.3. However, you can see that the [00:12:23] final code that you end up with is not [00:12:25] really intuitive. We had to make the [00:12:27] class partial because we need our [00:12:29] generators to be able to inject [00:12:31] marshalling code there, even though from [00:12:32] your perspective you're like, well, I [00:12:34] don't really need a generator. My class [00:12:36] it doesn't use anything. Why do I have [00:12:37] to do this? Uh and then we have this [00:12:40] dynamic Windows Runtime Cast attribute [00:12:41] that we have to add uh that is needed so [00:12:43] that we can [00:12:45] emit some code to make sure that [00:12:46] trimming doesn't remove types that we [00:12:48] actually might be relying on, in this [00:12:49] case this framework element, even though [00:12:51] from your point of view like why do I [00:12:52] need this attribute? I'm just trying to [00:12:54] cast an object. And then similarly on [00:12:56] the collection expression you can see [00:12:57] that we are having to add an explicit [00:12:59] cast to an array type uh because [00:13:01] implementation detail that collection [00:13:03] expression might result in a compiler [00:13:05] generated type that we cannot see, [00:13:06] meaning that we cannot generate [00:13:07] marshalling code from it, even though [00:13:09] again from your perspective you're just [00:13:10] using a collection expression. You just [00:13:11] want it to work. You're just creating a [00:13:13] sequence of elements and you want a [00:13:15] native consumer to work. So, the whole [00:13:16] thing in general is just not really um [00:13:20] developer friendly, and so we spent a [00:13:22] lot of time on reworking CSLA [00:13:24] to make sure that all of this scenario [00:13:25] would just work. And so the new code [00:13:27] that you can use for this in CSLA is a [00:13:29] CSLA 3.0 is exactly the first iteration [00:13:32] that you would have written. So, no need [00:13:33] to mark anything as partial, no need to [00:13:35] add attributes anywhere, no need to add [00:13:37] cast anywhere. The code is just working [00:13:39] as is with no changes required on your [00:13:41] end. So, we hope that with the move to [00:13:43] CSLA 3.0 things will just be much more [00:13:45] convenient to use for you. [00:13:48] >> So, you heard so you talk about the [00:13:49] worsening problems that we had. So, the [00:13:51] way we had solved that is basically [00:13:53] making all of our projection DLLs [00:13:55] reference DLLs or what we call reference [00:13:57] projections. [00:13:58] So, anyone who's shipping projections [00:14:00] will be shipping assemblies that are [00:14:02] reference DLLs. They would just describe [00:14:04] the API API surface of the component, [00:14:07] but it's not going to have any actual [00:14:08] implementation case and details in those [00:14:10] DLLs. [00:14:11] There's a lib file that will still be [00:14:13] shipped, [00:14:14] but it's going to be a DLL that has a [00:14:16] bunch of forwarder that say all of the [00:14:18] types from that DLL are forwarded to [00:14:20] this another DLL that we're going to [00:14:21] generate later on the app actually both. [00:14:24] And the way we're going to be able to do [00:14:25] that is components and NuGet packages [00:14:27] will be able to have the metadata WinMD [00:14:29] files inside of this metadata folder. [00:14:32] And basically when the app builds [00:14:34] we're going to go pick up all of these [00:14:35] WinMD files and go generate this merge [00:14:38] projection where we gather each one of [00:14:40] these WinMD files, we generate a [00:14:41] projection for it and we put it in this [00:14:43] one DLL called WinRT projection.dll. [00:14:46] Similarly, we are going to go analyze [00:14:47] your your entire app for all of the [00:14:49] modules that you're referencing and [00:14:51] figure out what WinRT scenarios are you [00:14:52] using in your app. [00:14:54] Do you have a class implementing WinRT [00:14:55] interfaces? In that case you may be [00:14:57] passing that across the WinRT API. So we [00:14:59] will go figure that all out and we go [00:15:01] generate all of the interop code that's [00:15:03] needed to enable those scenarios. [00:15:05] And that will go in a separate DLL [00:15:07] called WinRT.interop.dll. [00:15:08] But basically what we achieve is that [00:15:10] now the app developer is the one that's [00:15:13] deciding which CS WinRT version is used [00:15:15] to go actually generate the the actual [00:15:17] implementation of these projections. [00:15:19] So we avoid all of the versioning [00:15:20] problem that Sergio was talking about [00:15:22] earlier. [00:15:23] And it is so and this means that the [00:15:24] libraries who have CS WinRT projections [00:15:27] that are distributing they just have no [00:15:29] implementation but just the API surface [00:15:31] and then the app actually puts in those [00:15:32] implementation when we go generate them [00:15:34] here. [00:15:35] And thereby the app developer is in [00:15:36] control of the CS WinRT version. [00:15:41] So CS 93.0 is a breaking change but we [00:15:44] want to make sure that we're not forcing [00:15:45] folks into the breaking change but [00:15:47] you're able to move at your own pace and [00:15:49] move to CS 23.0 projections when you're [00:15:51] ready. So we worked with the .NET SDK [00:15:53] team and the NuGet team to go as support [00:15:56] for that site that you can move forward [00:15:58] using the target framework. So we worked [00:16:00] with them for that the last bit in the [00:16:02] OS version in the TFM typically has [00:16:04] always been zero and that will continue [00:16:06] to mean that you're using CS 92.x or [00:16:09] earlier projection. [00:16:10] But if you change that to .1 that will [00:16:13] mean that you're moving to CS 93.0 [00:16:15] projections. [00:16:16] And this way you're now able to move at [00:16:19] your own pace to CS22.0 and if you're a [00:16:22] NuGet component package that ships [00:16:24] either projections or you had [00:16:25] dependencies on CSMRT projections, [00:16:28] you're able to multi-target. So you [00:16:29] could have your CS22.x projections in [00:16:32] one folder and your CS23.0 projections [00:16:35] in another folder with the .1 TFM. And [00:16:37] this means your consumers are able to [00:16:39] also move at their own pace to CS23.0 [00:16:41] when they want to. [00:16:44] And to help libraries [00:16:47] adopt and multi-target with CS23.0, we [00:16:50] went and added this define called CS23_0 [00:16:54] where you could conditionally include [00:16:55] CS23.0 compatible code versus 2.x code. [00:16:59] So in this case, for instance, [00:17:01] we had a Windows Foundation that typed a [00:17:03] Win handler, which is a type that we [00:17:05] used to project ourselves. [00:17:06] Uh but now .NET has a clone type called [00:17:08] System.Win handler that takes both two [00:17:10] generics. So we're able to go take [00:17:12] advantage of that in CS22.0. And so you [00:17:15] could conditionally write the code for [00:17:17] CS22.0 and [00:17:19] fall back code of the previous code for [00:17:20] CS22.x and based on which [00:17:24] TFM your library is being built for, the [00:17:26] right one will be selected and compiled [00:17:28] in. [00:17:30] >> So we mentioned before how CS23 is a [00:17:32] breaking change and Mano mentioned some [00:17:34] of the API surface changes that we also [00:17:36] did, for instance, for system event [00:17:37] handler. I want to cover how we also [00:17:40] went back and looked at all the API [00:17:42] surface that we had and tried to find [00:17:44] improvements that we could do given that [00:17:46] we had the opportunity to actually [00:17:47] change those now that we're making a [00:17:48] breaking change. And so one area that we [00:17:50] focused on was the way that we marshal [00:17:52] WinRT arrays. So just for context, WinRT [00:17:55] has three different ways that you can [00:17:56] pass or you can define arrays in a WinRT [00:17:59] function. You have pass arrays, which [00:18:01] are arrays given as an input to a collie [00:18:04] where the collie can just read values [00:18:05] from those from that array. Uh you have [00:18:07] fill arrays, which are arrays that are [00:18:09] given collie returns can write into. So [00:18:12] you just pass an empty array and that [00:18:13] collie can just populate values in that [00:18:15] array. And then you have receive arrays, [00:18:18] which are just arrays that a given [00:18:19] method will just create, uh, populate it [00:18:21] and will just return it back to you [00:18:23] either as an out parameter or as as a [00:18:24] return value. Now, historically, like on [00:18:27] .NET framework, on [00:18:29] We always projected all three of these [00:18:30] as just normal arrays. So no matter if, [00:18:32] uh, the semantics was different, like if [00:18:34] you could just write into them, read [00:18:36] from them, you would just have to use an [00:18:38] array, which wasn't not really that [00:18:39] convenient or flexible. And so now that [00:18:42] we have, you know, we can target modern [00:18:43] .NET and modern C Sharp features, uh, we [00:18:45] actually decided to change this to take [00:18:47] advantage of the new span types. And so [00:18:49] in particular, we're now as of C# 3.0, [00:18:52] we're going to project pass arrays as [00:18:54] with only spans and fill arrays as [00:18:56] spans. So this gives you more [00:18:58] flexibility. It is still source [00:18:59] compatible because we take advantage of [00:19:01] the C# 14 feature first class span where [00:19:03] you can pass an array or, uh, if you [00:19:06] already have a span or maybe you pass a [00:19:07] string as a read only span of characters [00:19:09] and Roslyn will automatically emit code [00:19:11] where needed to create a span for you. [00:19:13] And you get a lot of benefits from this. [00:19:15] You get, uh, for instance, zero [00:19:16] allocation if you use a stack alloc [00:19:18] pattern in some scenarios. You don't you [00:19:19] don't like you don't actually need a [00:19:21] concrete array to pass. Uh, you no [00:19:23] longer even need exactly sized arrays in [00:19:25] some scenarios. And so in general, you [00:19:27] also get a less memory pressure and it [00:19:28] just gives you like more flexibility in [00:19:30] general. So here we can see an actual [00:19:32] example in practice that compares C# 2 [00:19:35] with C# 3. Imagine we have some array [00:19:38] that we got from somewhere, this data [00:19:40] array that we have here. And then we [00:19:41] have some WinRT object which is a data [00:19:43] reader and we want to read some bytes, [00:19:46] in this case exactly 16, and we're [00:19:47] reading some header from a given buffer. [00:19:49] And we want to write those into a given [00:19:51] subsection of that initial array. In C# [00:19:54] uh, because all these WinRT APIs will [00:19:56] only take an array no matter what, which [00:19:58] had to be exactly sized, we would have [00:20:00] to allocate a new temporary array with [00:20:02] the size that we want. We pass that to [00:20:04] read bytes and that will populate those [00:20:06] values. And then we have to copy the [00:20:09] values from this temporary array back [00:20:10] into the target range that we care about [00:20:12] in the initial array. And then we we're [00:20:14] just left with this temporary array that [00:20:15] we just throw out. Uh, we could optimize [00:20:18] things a little bit by, for instance, [00:20:19] pooling that array, but it still adds a [00:20:21] lot more complexity, it's more error [00:20:23] prone, and still not really intuitive to [00:20:24] use or as efficient as it could be. [00:20:27] And here on the right, instead, you can [00:20:28] see what this looks like in CS 23. So, [00:20:30] we still have our initial data that we [00:20:31] got from somewhere, but then we no [00:20:33] longer need to allocate a temporary, we [00:20:35] no longer need to copy anything. We just [00:20:37] slice the array as a span with the [00:20:38] target range that we want, and then we [00:20:40] just pass that. And so the whole thing [00:20:41] becomes just a one-liner, which is both [00:20:44] more efficient, but also much easier to [00:20:45] read and to maintain. So we're hoping [00:20:47] that with CS 23 consuming WinRT APIs [00:20:50] will feel just more familiar to people [00:20:53] who are just used to writing modern C# [00:20:55] and .NET code. [00:20:57] >> So now let's go see a demo where we are [00:20:59] going to move the Contoso Camera app to [00:21:01] CS 13.0. [00:21:03] So let me jump into Visual Studio. [00:21:09] So here we have the Contoso Camera app. [00:21:12] And right, so the first thing I'm going [00:21:14] to go do is I'm going to go change the [00:21:16] TFM. [00:21:17] >> We need to use the dot one, right? [00:21:18] >> Mhm. [00:21:19] And I'm going to go also move it to [00:21:20] 0.11. [00:21:21] >> Right. [00:21:23] >> And then [00:21:25] I have a cheat sheet here at the bottom [00:21:27] with my version numbers. So [00:21:29] this is using the CS 9 NuGet package [00:21:31] that we actually released earlier this [00:21:32] week. [00:21:35] So I'm going to go update to that. I'm [00:21:36] going to go update my Windows SDK [00:21:38] package version, which is also a version [00:21:40] that we released earlier this week. [00:21:42] >> This is all still because all of this is [00:21:44] currently in preview, right? Like once [00:21:45] we ship to stable, people will just be [00:21:46] able to target that one and then things [00:21:48] should just work. [00:21:49] >> Mhm. [00:21:50] And then we are working with the WinUI [00:21:52] and WinAppSDK team for them to [00:21:53] multi-target. This is a internal package [00:21:56] at the moment, but we're hoping to get [00:21:57] this out very soon. [00:21:59] I'm going to go update that. [00:22:02] And so basically we have we we updated [00:22:04] to dot one TFM. [00:22:06] We updated it to specify the CS T [00:22:08] version 3.0. [00:22:09] >> Mhm. [00:22:09] >> And we fast specified the Windows SDK [00:22:11] package version, which is 88 preview, [00:22:13] which is the one that's compatible with [00:22:14] the latest. [00:22:16] And let's go to build. [00:22:20] And we're going to see a bunch of build [00:22:21] breaks because [00:22:25] we talked about those various breaking [00:22:26] changes. [00:22:27] >> So let's take a look at a couple. [00:22:32] So in this case, we had the system [00:22:34] runtime interrupt [00:22:36] We're actually not using its namespace [00:22:37] anymore. [00:22:38] >> And because we moved those extensions [00:22:40] just into Windows Foundation, right? So [00:22:42] it's even more convenient. We need to [00:22:43] add the using anymore. This is to be [00:22:45] able to await WinRT available, right? [00:22:47] >> Yep. Mhm. And now here's the [00:22:50] same instance of that that I'm going to [00:22:51] go remove. [00:22:53] Then we saw those dynamic Windows [00:22:55] runtime cast attributes that were needed [00:22:57] as a [00:22:58] to get working with [00:23:00] >> Right. [00:23:02] >> We don't need those anymore. [00:23:03] >> This is going to clean up code so much. [00:23:05] We have almost a thousand of these [00:23:07] sprinkled all over the Microsoft store [00:23:09] codebase. So the fact that it just works [00:23:11] is much nicer. [00:23:12] >> And we also went and fixed the point [00:23:16] rect and size to reflect the actual ABI [00:23:18] types. [00:23:19] >> So instead of being doubles, it's now [00:23:21] just float, which matches WinRT. [00:23:23] Which is also more efficient, right? [00:23:24] Because before we were doing a lot of [00:23:26] implicit conversions to and from floats [00:23:28] and doubles for no reason. [00:23:29] >> Yeah, before when you passed it, then we [00:23:30] were doing the casting and so on. [00:23:32] So [00:23:33] you can see the rest of the errors are [00:23:35] of a similar pattern. [00:23:37] So what I'm going to do is I already [00:23:38] went through all of these errors and I [00:23:40] converted them. And here I moved over to [00:23:43] my other instance where I have done the [00:23:45] migration already. So you can see it's [00:23:47] using that one TFM. [00:23:49] It has the new version numbers that we [00:23:50] just moved it to. [00:23:52] I'm going to go build this. [00:23:56] >> In general, it's all like mechanical [00:23:57] changes, right? There's nothing major [00:23:58] that I need to rewrite or refactor. [00:24:00] >> I hope is that we could have some code [00:24:02] fixer or [00:24:04] some agent-driven migration thing to [00:24:06] help migrate projects. [00:24:08] So here we could see that we have one [00:24:10] time we're processing the all the [00:24:12] We're generating a [00:24:14] the [00:24:16] And then we are going to go analyze and [00:24:18] figure out all the DLLs that you're [00:24:19] referencing and go generate [00:24:23] And [00:24:25] they must go at different spaces. So [00:24:30] >> We [00:24:30] >> have incremental builds for all these [00:24:31] tools, right? So, just the first build [00:24:33] takes a little bit longer, but then all [00:24:34] the other ones should be faster. [00:24:38] >> So, we added the old F build [00:24:40] and now let's run it. [00:24:48] >> It's coming up. [00:24:49] >> Mhm. [00:24:51] >> Oh, there it is. [00:24:51] >> And it launches. [00:24:52] >> Nice. [00:24:55] >> So, going back to the actual [00:24:57] presentation. [00:25:03] So, what's next? So, we working without [00:25:04] partner teams such as WinAppSDK for them [00:25:06] to go multi-target and distribute both [00:25:09] CS 1.2.x and CS 1.2.0 projections. [00:25:12] If you don't not have any dependencies [00:25:14] today and just using the Windows SDK [00:25:15] projection itself, you can go try it out [00:25:17] right now with the .1 TFM [00:25:19] and you we have a NuGet link at the [00:25:20] bottom here [00:25:22] and you could go check out our release [00:25:23] notes for all the breaking changes that [00:25:24] we did [00:25:25] and [00:25:26] you could boot your .1 TFM and try [00:25:28] building and provide feedback. But if [00:25:30] you do have dependencies such as [00:25:31] WinAppSDK, we working with those teams [00:25:32] to get their target packages [00:25:34] multi-targeted and once those [00:25:36] preview builds are out, we asked you to [00:25:38] go try those out and provide us with [00:25:39] feedback. [00:25:40] Based on the feedback that we get, we'll [00:25:42] be looking at moving CS 1.2.0 from [00:25:44] preview to stable. [00:25:47] Thank you. So, we have also a GitHub [00:25:49] link here. So, if you have any feedback, [00:25:51] feel free to open an issue there.