{"id":2078,"date":"2017-09-27T11:55:00","date_gmt":"2017-09-27T14:55:00","guid":{"rendered":"http:\/\/gianfratti.com\/?p=2078"},"modified":"2017-09-27T15:32:55","modified_gmt":"2017-09-27T18:32:55","slug":"o-compilador-roslyn-csc-exe-e-vbc-exe-e-a-hospedagem-compartilhada","status":"publish","type":"post","link":"https:\/\/gianfratti.com\/index.php\/o-compilador-roslyn-csc-exe-e-vbc-exe-e-a-hospedagem-compartilhada\/","title":{"rendered":"O compilador Roslyn (csc.exe  e vbc.exe ) e a hospedagem compartilhada"},"content":{"rendered":"<p><span style=\"font-family: Segoe UI; font-size: large;\"><span style=\"font-family: Segoe UI; font-size: large;\"> A compila\u00e7\u00e3o <strong>Roslyn<\/strong> (<span id=\"wiki-tooltip-1\" data-tooltip-content=\"#wiki-tooltip-box-1\" data-wiki_num=\"1\" data-wiki_id=\"33644243\" data-wiki_title=\"Roslyn (compiler)\" data-wiki_section=\"\" data-wiki_base_url=\"https:\/\/en.wikipedia.org\/w\/api.php\" data-wiki_url=\"https:\/\/en.wikipedia.org\/wiki\/Roslyn_(compiler)\" data-wiki_thumbnail=\"default\" data-wiki_nonce=\"3a9158fb6a\"><a class=\"wiki-tooltip\" href=\"https:\/\/en.wikipedia.org\/wiki\/Roslyn_(compiler)\" target=\"_blank\" rel=\"noopener noreferrer\" onclick=\"return isClickEnabled( 'hover', '' );\">.NET Compiler Platform<\/a><\/span>), agora \u00e9 padr\u00e3o a partir<\/span> da <b>vers\u00e3o 4.5 da plataforma .NET<\/b>, e isso significa que se voc\u00ea criar qualquer aplica\u00e7\u00e3o web, <span style=\"color: #0000ff;\">Web Forms ou MVC,<\/span> voc\u00ea ter\u00e1 o compilador Roslyn pr\u00e9-instalado em seu projeto na pasta <b>bin<\/b> dentro da pasta <b>roslyn<\/b>:<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2079\" src=\"http:\/\/gianfratti.com\/wp-content\/uploads\/2017\/09\/net_rosl11.png\" alt=\"\" width=\"472\" height=\"244\" srcset=\"https:\/\/gianfratti.com\/wp-content\/uploads\/2017\/09\/net_rosl11.png 472w, https:\/\/gianfratti.com\/wp-content\/uploads\/2017\/09\/net_rosl11-300x155.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/span><br \/>\n<!--more--><br \/>\n<span style=\"color: #000080; font-family: Segoe UI; font-size: x-large;\">Porque usar a compila\u00e7\u00e3o Roslyn ?<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Ao usar a compila\u00e7\u00e3o Roslyn voc\u00ea tem acesso a muitos recursos durante o desenvolvimento do seu aplicativo e tamb\u00e9m durante a implanta\u00e7\u00e3o no servidor.<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Apenas para citar algumas das vantagens:<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">&#8211; Durante o desenvolvimento da aplica\u00e7\u00e3o<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Antes do Roslyn quando voc\u00ea fazia qualquer altera\u00e7\u00e3o no seu c\u00f3digo (C#. VB .NET), era preciso realizar um build para ver o resultado no navegador. Com o Rosyln isso n\u00e3o \u00e9 mais necess\u00e1rio.<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">&#8211; Durante a implanta\u00e7\u00e3o no servidor<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Ao desenvolver uma aplica\u00e7\u00e3o Web escrevemos c\u00f3digo C# e HTML mesclados nas p\u00e1ginas ASPX ou nas views MVC e isso requer algum tipo de compila\u00e7\u00e3o para exibir o resultado ao usu\u00e1rio afetando o tempo de carregamento da p\u00e1gina. Dessa forma usando o Roslyn essa compila\u00e7\u00e3o n\u00e3o ser\u00e1 necess\u00e1ria e o tempo de carga da p\u00e1gina vai melhorar.<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Assim somente esses dois benef\u00edcios j\u00e1 valeria a pena usar o Roslyn. Existem mais recursos que o Roslyn possui e eu n\u00e3o citei aqui. Para detalhes veja as refer\u00eancias.<\/span><\/p>\n<p><span style=\"color: #000080; font-family: Segoe UI; font-size: x-large;\">O problema do Roslyn em hospedagem compartilhada<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Se voc\u00ea est\u00e1 tentando publicar sua aplica\u00e7\u00e3o com o Roslyn em hospedagem compartilhada, voc\u00ea pode ter problemas.<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Quando vamos fazer a implanta\u00e7\u00e3o de uma aplica\u00e7\u00e3o no servidor ela \u00e9 executada no modo <b>Full Trust<\/b> <i>(confian\u00e7a total),<\/i> e, empresas de hospedagem compartilhadas n\u00e3o permitem que aplicativos executem no modo Full Trust. Em geral elas substituem o<b> Full Trust<\/b> por <b>Medium Trust<\/b> devido a restri\u00e7\u00f5es de seguran\u00e7a, visto que, elas hospedam sites de diversos clientes e assim evitam que uma aplica\u00e7\u00e3o web de um cliente afete a aplica\u00e7\u00e3o de outro cliente.<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">A compila\u00e7\u00e3o Roslyn <u>somente vai funcionar<\/u> em modo <b>Full Trust, <\/b>e, dessa forma em ambientes compartilhados, voc\u00ea ter\u00e1 problemas se a sua hospedagem n\u00e3o permitir esse modo.<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Se a hospedagem compartilhada n\u00e3o der suporte ao modo Full Trust voc\u00ea n\u00e3o poder\u00e1 implantar a sua aplica\u00e7\u00e3o usando o Roslyn<\/span><\/p>\n<p><span style=\"color: #800080; font-family: Segoe UI; font-size: x-large;\">O que fazer agora? <\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Como implantar a sua aplica\u00e7\u00e3o web sem o Roslyn em servidores compartilhados?<\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\"> Felizmente voc\u00ea pode implantar a sua aplica\u00e7\u00e3o sem o Roslyn e n\u00e3o precisa fazer nenhuma mudan\u00e7a no c\u00f3digo. <\/span><\/p>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Abra a janela do Gerenciador de pacotes <b>NuGet<\/b> e desinstale os pacotes :<\/span><\/p>\n<ul>\n<li><span style=\"color: #000080; font-family: Segoe UI; font-size: large;\">&#8220;Microsoft.CodeDom.Providers.DotNetCompilerPlatform&#8221; <\/span><\/li>\n<li><span style=\"color: #000080; font-family: Segoe UI; font-size: large;\">&#8220;Microsoft.Net.Compilers&#8221;<\/span><\/li>\n<\/ul>\n<p><span style=\"font-family: Segoe UI; font-size: large;\">Esta desinstala\u00e7\u00e3o tamb\u00e9m vai remover a configura\u00e7\u00e3o <b>CodeDom<\/b> do arquivo <b> web.config<\/b> e isso vai resolver o problema.<\/span><\/p>\n<p>Fonte: <a href=\"http:\/\/www.macoratti.net\/16\/05\/net_rosl1.htm\" target=\"_blank\" rel=\"noopener\">http:\/\/www.macoratti.net\/16\/05\/net_rosl1.htm<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A compila\u00e7\u00e3o Roslyn (), agora \u00e9 padr\u00e3o a partir da vers\u00e3o 4.5 da plataforma .NET, e isso significa que se voc\u00ea criar qualquer aplica\u00e7\u00e3o web, Web Forms ou MVC, voc\u00ea ter\u00e1 o compilador Roslyn pr\u00e9-instalado em seu projeto na pasta bin dentro da pasta roslyn:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2,174,178],"tags":[206],"class_list":["post-2078","post","type-post","status-publish","format-standard","hentry","category-net-framework","category-melhores-praticas","category-qualidade-software","tag-roslyn"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/2078","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/comments?post=2078"}],"version-history":[{"count":8,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/2078\/revisions"}],"predecessor-version":[{"id":2082,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/posts\/2078\/revisions\/2082"}],"wp:attachment":[{"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/media?parent=2078"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/categories?post=2078"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gianfratti.com\/index.php\/wp-json\/wp\/v2\/tags?post=2078"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}