{"id":5583,"date":"2016-04-02T15:34:19","date_gmt":"2016-04-02T15:34:19","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/dotnet\/?p=5583"},"modified":"2021-09-30T12:03:55","modified_gmt":"2021-09-30T19:03:55","slug":"whats-new-for-c-and-vb-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/whats-new-for-c-and-vb-in-visual-studio\/","title":{"rendered":"What\u2019s New for C# and VB in Visual Studio"},"content":{"rendered":"<p>This week at Build 2016, we released <a title=\"Visual Studio 2015 Update 2\" href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/2016\/03\/30\/visual-studio-2015-update-2-rtm\/\">Visual Studio 2015 Update 2<\/a> and <a title=\"Visual Studio &quot;15&quot; Preview\" href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/visual-studio-15-preview\/\">Visual Studio \u201c15\u201d Preview<\/a>. Both releases include many new language features that you can try today. It\u2019s safe to install both versions of Visual Studio on the same machine so that you can check out all of the new features for yourself.<\/p>\n<ul>\n<li><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=691129\">Download Visual Studio Update 2<\/a><\/li>\n<li><a href=\"https:\/\/www.visualstudio.com\/en-us\/downloads\/update2-prereleases\">Download Visual Studio \u201c15\u201d Preview<\/a><\/li>\n<\/ul>\n<h2>New C# and VB features in Visual Studio 2015 Update 2<\/h2>\n<p>In <a href=\"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/2016\/03\/30\/visual-studio-2015-update-2-rtm\/\">Visual Studio 2015 Update 2<\/a>, you\u2019ll notice that we\u2019ve added some enhancements to previous features as well as added some new refactorings. The team focused on improving developer productivity by cutting down time, mouse-clicks, and keystrokes to make the actions you perform every day more efficient.<\/p>\n<p><strong>Interactive Improvements (C# only in Update 2, VB planned for future)<\/strong><\/p>\n<p>The C# Interactive window and command-line REPL, csi, were introduced in Visual Studio Update 1. In Update 2, we\u2019ve paired the interactive experience with the editor by allowing developers to send code snippets from the editor to be executed in the Interactive window. We\u2019ve also enabled developers to initialize the Interactive window with a project\u2019s context.<\/p>\n<p>To play with these features:<\/p>\n<ul>\n<li>Highlight a code snippet in the editor, right-click, and press <strong>Execute in Interactive<\/strong> (or Ctrl+E, Ctrl+E), as shown in the image below.<\/li>\n<li>Right-click on a project in the Solution Explorer and press <strong>Initialize Interactive<\/strong> with project.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/03\/clip_image0029.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-5472\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/clip_image0029.png\" alt=\"clip_image0029.png\" width=\"626\" height=\"433\" \/><\/a><\/p>\n<p><strong>Add Imports\/Using Improvements (VB and C# in Update 2)<\/strong><\/p>\n<p>We\u2019ve improved the Adding Imports\/Using command to support \u201cfuzzy\u201d matching on misspelled types and to search your entire solution and metadata for the correct type\u2014adding both a using\/imports and any project\/metadata references, if necessary.<\/p>\n<p>You can see an example of this feature with a misspelled \u201cWebCleint\u201d type. The type name needs to be fixed (two letters are transposed) and the System.Net using needs to be added.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/03\/clip_image0046.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-5481\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/clip_image0046.png\" alt=\"clip_image0046.png\" width=\"626\" height=\"239\" \/><\/a><\/p>\n<p><strong>Refactorings<\/strong><\/p>\n<p>A couple refactorings we sprinkled in were:<\/p>\n<ul>\n<li>Make method synchronous (VB and C# in Update 2)<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-5795\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/vb-make-synchronous.png\" alt=\"vb-make-synchronous\" width=\"623\" height=\"253\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/vb-make-synchronous.png 623w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/vb-make-synchronous-300x122.png 300w\" sizes=\"(max-width: 623px) 100vw, 623px\" \/><\/p>\n<ul>\n<li>Use null-conditional for delegate invocation (C# only in Update 2, Maybe for VB? &#8211; Read More below)<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>So, the killer scenario for this feature is raising events in a thread-safe way. Prior to C# 6 the\u00a0<em>proper<\/em> way to do this was to copy the backing field of the event to a local variable, check the variable for null-ness and invoke the delegate inside the if. Otherwise Thread B could set the\u00a0delegate to\u00a0null by removing the last handler <em>after<\/em>\u00a0Thread A\u00a0has checked it for null resulting in Thread A unintentionally throwing a NullReferenceException. Using the null-conditional in C# is a much shorter form of this pattern. But in VB the RaiseEvent statement\u00a0<em>already<\/em>\u00a0raised the event in a null safe way, using the same code-gen. So the killer scenario for this refactoring really didn&#8217;t exist and worse, if we add the refactoring people might mistakenly change their code to be less idiomatic with no benefit. From time to time we review samples that don&#8217;t understand this and perform the null check explicitly anyway so this seems likely to reinforce that redundant behavior. Let us know in the comments if you think the refactoring still has tons of value for you outside of raising events and we&#8217;ll reconsider! <strong>-ADG<\/strong>\n<!--more--><\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/03\/clip_image0067.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-5491\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/clip_image0067.png\" alt=\"clip_image0067.png\" width=\"626\" height=\"326\" \/><\/a><\/p>\n<p><strong>Roslyn Features (VB and C# in Update 2)<\/strong><\/p>\n<p>We\u2019ve added two new compiler flags to the <a href=\"https:\/\/github.com\/dotnet\/roslyn\">Roslyn compiler<\/a>:<\/p>\n<ul>\n<li><strong>deterministic<\/strong>: This switch will ensure builds with the same inputs produce the same the outputs, byte for byte. Previously, PE entries&#8211;like MVID, PDB ID and Timestamp&#8211;would change on every build but now can be calculated deterministically based on the inputs.<\/li>\n<li><strong>publicSign<\/strong>: Supports a new method of signing that is similar to delay signing except it doesn\u2019t need to add skip verification entries to your machine. Binaries can be public signed with only the public key and load into contexts necessary for development and testing. This is also known as <a href=\"https:\/\/github.com\/dotnet\/corefx\/blob\/master\/Documentation\/project-docs\/\">OSS signing<\/a>.<\/li>\n<\/ul>\n<h2>Sneak Peek: What\u2019s in Visual Studio \u201c15\u201d Preview<\/h2>\n<p>We released a first look of Visual Studio \u201c15\u201d this week at Build. It is point in time view of what we\u2019ve been working on. Some features will still change and others are still coming. It\u2019s a good opportunity to provide feedback on the next big release of Visual Studio.<\/p>\n<p><strong>Play with C# 7 Prototypes (VB 15 Prototypes planned)<\/strong><\/p>\n<p>The guiding theme for C# 7 language design is \u201cworking with data\u201d. While the final feature set for C# 7 is still being determined by the Language Design Committee, you can play with some of our language feature prototypes today in <a href=\"https:\/\/www.visualstudio.com\/downloads\/visual-studio-next-downloads-vs\">Visual Studio \u201c15\u201d Preview<\/a>.<\/p>\n<p>To access the language prototypes, right-click on your project in Solution Explorer &gt; Properties &gt; Build and type \u201c__DEMO__\u201d in the \u201cConditional compilation symbols\u201d text box. This will enable you to play with a preview of local functions, digit separators, binary literals, ref returns, and pattern matching.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/conditional2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-5543\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/conditional2.png\" alt=\"conditional\" width=\"600\" \/><\/a><\/p>\n<p>There is a known bug related to ref return IntelliSense, which can be worked around by:<\/p>\n<ul>\n<li>right-click on your project in Solution Explorer &gt; Unload Project<\/li>\n<li>right-click on your project after it\u2019s been unloaded &gt; Edit csproj<\/li>\n<li>in the first Property Group under &lt;AssemblyName&gt; add: &lt;Features&gt;refLocalsAndReturns&lt;\/Features&gt;<\/li>\n<li>Ignore any XML schema warnings you may see<\/li>\n<\/ul>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/features2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-5571\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/features2.png\" alt=\"features\" width=\"975\" height=\"35\" \/><\/a><\/p>\n<p><strong>Custom Code Style Enforcement (VB and C# in Visual Studio &#8220;15&#8221; Preview)<\/strong><\/p>\n<p>The feature you all have been asking for is almost here! In Visual Studio \u201c15\u201d Preview, you can play around and give us feedback on our initial prototype for customizable code style enforcement. To see the style options we support today, go to Tools &gt; Options &gt; C#\/VB &gt; Code Style. Under the General options, you can tweak \u201cthis.\u201d\/&#8221;Me.&#8221;, predefined type, and \u201cvar&#8221;\/type inference preferences. Today, with \u201cvar\u2019 preferences, you can control the severity of enforcement\u2014e.g., I can prefer \u201cvar\u201d over explicit types for built-in types and make any violation of this squiggle as an error in the editor.<\/p>\n<p>&nbsp;<\/p>\n<p>You can also add Naming rules, for instance, to require methods to be PascalCase.<\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/vb-style-window.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-5785\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/vb-style-window.png\" alt=\"vb-style-window\" width=\"743\" height=\"434\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/vb-style-window.png 743w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/vb-style-window-300x175.png 300w\" sizes=\"(max-width: 743px) 100vw, 743px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/style-enforcement.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-5522\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/style-enforcement.png\" alt=\"style-enforcement\" width=\"600\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/style-enforcement.png 975w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/style-enforcement-300x174.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2016\/04\/style-enforcement-768x446.png 768w\" sizes=\"(max-width: 975px) 100vw, 975px\" \/><\/a><\/p>\n<h2>Please Keep up the Feedback<\/h2>\n<p>Thanks for all the feedback we\u2019ve received over the last year. It\u2019s had a big impact on the features that I\u2019ve described here and on others we\u2019ve been working on. Please keep it coming. The language feedback on the open source Roslyn project has been extensive. It\u2019s great to see a broader language community developing around the <a href=\"https:\/\/github.com\/dotnet\/roslyn\">Roslyn open source project<\/a> on Github.<\/p>\n<p>To give feedback, try one of the following places:<\/p>\n<ul>\n<li>The <a href=\"https:\/\/github.com\/dotnet\/roslyn\">Roslyn project<\/a>, for language feedback<\/li>\n<li><a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt280277.aspx\">Send Feedback Option<\/a> Visual Studio, for Visual Studio feedback<\/li>\n<li><a href=\"http:\/\/visualstudio.uservoice.com\/forums\/121579-visual-studio\">UserVoice<\/a> , for Visual Studio suggestions<\/li>\n<\/ul>\n<p>Thanks for using the product. I hope you enjoy using it to build your next app.<\/p>\n<p>Over \u2018n\u2019 out\nKasey Uhlenhuth, Program Manager,\u00a0Managed Languages Team<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week at Build 2016, we released Visual Studio 2015 Update 2 and Visual Studio \u201c15\u201d Preview. Both releases include many new language features that you can try today. It\u2019s safe to install both versions of Visual Studio on the same machine so that you can check out all of the new features for yourself. [&hellip;]<\/p>\n","protected":false},"author":336,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685],"tags":[],"class_list":["post-5583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet"],"acf":[],"blog_post_summary":"<p>This week at Build 2016, we released Visual Studio 2015 Update 2 and Visual Studio \u201c15\u201d Preview. Both releases include many new language features that you can try today. It\u2019s safe to install both versions of Visual Studio on the same machine so that you can check out all of the new features for yourself. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/5583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/336"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=5583"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/5583\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=5583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=5583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=5583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}