{"id":25147,"date":"2019-11-01T20:34:47","date_gmt":"2019-11-01T20:34:47","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=25147"},"modified":"2019-11-01T20:34:47","modified_gmt":"2019-11-01T20:34:47","slug":"an-update-on-cpp-cli-and-dotnet-core","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/an-update-on-cpp-cli-and-dotnet-core\/","title":{"rendered":"An Update on C++\/CLI and .NET Core"},"content":{"rendered":"<p>The first public release of our C++\/CLI support for .NET Core 3.1 is now available for public preview! It is included in <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">Visual Studio 2019 update 16.4 Preview 2<\/a>. We would love it if you could try it out and send us any feedback you have. For more info about what this is and the roadmap going forward, check out my last post on <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/the-future-of-cpp-cli-and-dotnet-core-3\/\">the future of C++\/CLI and .NET Core<\/a>.<\/p>\n<p>To get started make sure you have all the necessary components installed. C++\/CLI support for desktop development is an optional component, so you will need to select it on the installer\u2019s right pane:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25148 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/CoreCLI-Component.png\" alt=\"Install the \u201cDesktop development with C++\u201d workload and be sure to include the optional \u201cC++\/CLI support\u201d component.\" width=\"1290\" height=\"720\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/CoreCLI-Component.png 1290w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/CoreCLI-Component-300x167.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/CoreCLI-Component-768x429.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/CoreCLI-Component-1024x572.png 1024w\" sizes=\"(max-width: 1290px) 100vw, 1290px\" \/><\/p>\n<p>You will also need the .NET Core cross-platform development workload. It installs everything you need including the .NET Core 3.1 SDK:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25150 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-Workload.png\" alt=\"Alt: Install the \u201c.NET Core cross-platform development\u201d workload.\" width=\"1290\" height=\"720\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-Workload.png 1290w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-Workload-300x167.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-Workload-768x429.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-Workload-1024x572.png 1024w\" sizes=\"(max-width: 1290px) 100vw, 1290px\" \/><\/p>\n<h3>Creating a C++\/CLI .NET Core Project<\/h3>\n<p>First, you will want to create a \u201cCLR Class Library (.NET Core)\u201d or \u201cCLR Empty Project (.NET Code)\u201d. The Class library template includes some additional boiler plate to set up an example class and precompiled header that may make it easier to get started. The empty project is ideal for bringing in existing C++\/CLI code. Retargeting existing C++\/CLI projects to .NET Core isn\u2019t recommended.<\/p>\n<p>There isn\u2019t currently a template for C++\/CLI console or Windows applications that can be used with .NET Core. Instead you must put application entry point outside of the C++\/CLI code. In general, we strongly recommend keeping the C++\/CLI projects as narrow in scope as possible to handle just the interoperability between .NET Core and other C++ code.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25151 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-CLI-Project.png\" alt=\"\" width=\"1026\" height=\"712\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-CLI-Project.png 1026w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-CLI-Project-300x208.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-CLI-Project-768x533.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/NetCore-CLI-Project-1024x711.png 1024w\" sizes=\"(max-width: 1026px) 100vw, 1026px\" \/><\/p>\n<p>Once you create one of these projects, you can reference it from other .NET Core projects like any other class library \u2013 <strong>with one important caveat<\/strong>. .NET Core projects are typically architecture agnostic. You see this as the architecture \u201cAny CPU\u201d in the Configuration Manager and \u201cMSIL\u201d in the build logs. This is the default for all .NET Core projects. If you reference any C++\/CLI class libraries, you must specify an explicit architecture for the non-C++ projects instead of \u201cAny CPU\u201d.<\/p>\n<p>You can set a project\u2019s architecture by using the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-create-and-edit-configurations?view=vs-2019\">Configuration Manager<\/a>.<\/p>\n<p>If the architectures don\u2019t match, you will see this warning and attempting to load the C++\/CLI class library will fail at runtime:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25153 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/Processor-Mismatch-Warning.png\" alt=\"\u201cWarning MSB3270 There was a mismatch between the processor architecture of the project being built &quot;MSIL&quot; and the processor architecture of the reference\u2026\u201d\" width=\"622\" height=\"177\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/Processor-Mismatch-Warning.png 622w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2019\/10\/Processor-Mismatch-Warning-300x85.png 300w\" sizes=\"(max-width: 622px) 100vw, 622px\" \/><\/p>\n<p>To resolve this, make sure all projects in the solution are using the same architecture of \u201cx86\u201d and \u201cWin32\u201d or \u201cx64\u201d. If you are using ASP.NET Core, there is an additional consideration. Your projects also need to match the architecture of IIS Express. This is typically \u201cx64\u201d. If you see a \u201c500 server error\u201d due to the loader failing, this may be what the problem is.<\/p>\n<h3>Send us Feedback<\/h3>\n<p>Please try this out. We\u2019d love to hear your feedback\u00a0to\u00a0help us prioritize and\u00a0build the right features. We can be reached via the comments below or email (<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>).\u00a0You also can always send us general feedback via <a href=\"https:\/\/developercommunity.visualstudio.com\/\">Developer Community<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first public release of our C++\/CLI support for .NET Core 3.1 is now available for public preview! It is included in Visual Studio 2019 update 16.4 Preview 2. We would love it if you could try it out and send us any feedback you have. For more info about what this is and the [&hellip;]<\/p>\n","protected":false},"author":326,"featured_media":25151,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270],"tags":[86],"class_list":["post-25147","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","tag-ccli"],"acf":[],"blog_post_summary":"<p>The first public release of our C++\/CLI support for .NET Core 3.1 is now available for public preview! It is included in Visual Studio 2019 update 16.4 Preview 2. We would love it if you could try it out and send us any feedback you have. For more info about what this is and the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/326"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=25147"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/25147\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/25151"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=25147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=25147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=25147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}