<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Ural penguins - Сообщения с тегом csharp</title>
  <id>http://uralbash.ru/blog/tag/csharp/atom.xml</id>
  <updated>2017-09-01T21:35:00Z</updated>
  <link href="http://uralbash.ru/" />
  <link href="http://uralbash.ru/blog/tag/csharp/atom.xml" rel="self" />
  <generator uri="http://ablog.readthedocs.org" version="0.8.4">ABlog</generator>
  <entry xml:base="http://uralbash.ru/blog/tag/csharp/atom.xml">
    <title type="text">C# .Net Core для Linux</title>
    <id>http://uralbash.ru/articles/2017/netcore/</id>
    <updated>2017-09-01T21:35:00Z</updated>
    <published>2017-09-01T21:35:00Z</published>
    <link href="http://uralbash.ru/articles/2017/netcore/" />
    <author>
      <name>Uralbash</name>
    </author>
    <content type="html">&lt;div class=&quot;section&quot; id=&quot;c-net-core-linux&quot;&gt;

&lt;p&gt;Благодаря популярности &lt;code class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;Java&lt;/span&gt;&lt;/code&gt; язык &lt;code class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;C#&lt;/span&gt;&lt;/code&gt; обрел ещё большую популярность, да
так, что теперь доступен на &lt;cite&gt;Linux&lt;/cite&gt;. Я конечно не испытываю симпатий к этим
языкам и &lt;code class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.Net&lt;/span&gt;&lt;/code&gt; стеку в целом, но &lt;cite&gt;OpenSource&lt;/cite&gt; и доступность в &lt;cite&gt;Linux&lt;/cite&gt; не
может не радовать. Ниже рассмотрим пример как развернуть проект на &lt;code class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.NET&lt;/span&gt;
&lt;span class=&quot;pre&quot;&gt;Core&lt;/span&gt;&lt;/code&gt; и отправить &lt;cite&gt;HTTP&lt;/cite&gt; запрос.&lt;/p&gt;
&lt;div class=&quot;admonition note&quot;&gt;
&lt;p class=&quot;first admonition-title&quot;&gt;Примечание&lt;/p&gt;
&lt;p class=&quot;last&quot;&gt;Это статья из лекций
&lt;a class=&quot;reference external&quot; href=&quot;http://lecturesnet.readthedocs.io/net/requests/csharp.html&quot;&gt;http://lecturesnet.readthedocs.io/net/requests/csharp.html&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;c&quot;&gt;
&lt;h2&gt;C#&lt;/h2&gt;
&lt;div class=&quot;admonition seealso&quot;&gt;
&lt;p class=&quot;first admonition-title&quot;&gt;См.также&lt;/p&gt;
&lt;ul class=&quot;last simple&quot;&gt;
&lt;li&gt;&lt;a class=&quot;reference external&quot; href=&quot;https://www.microsoft.com/net/download/linux&quot;&gt;https://www.microsoft.com/net/download/linux&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;reference external&quot; href=&quot;https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient&quot;&gt;HttpClient Class&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a class=&quot;reference external&quot; href=&quot;https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient&quot;&gt;HttpClient Class&lt;/a&gt;
содержится в поставке &lt;code class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;.NET&lt;/span&gt; &lt;span class=&quot;pre&quot;&gt;Core&lt;/span&gt;&lt;/code&gt; для &lt;code class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;Linux&lt;/span&gt;&lt;/code&gt;. Создадим проект на C#
отправляющий HTTP запрос.&lt;/p&gt;
&lt;p&gt;Первой командой создается проект из шаблона, затем устанавливаются зависимости
и запускается программа.&lt;/p&gt;
&lt;div class=&quot;highlight-bash&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ dotnet new Console
$ dotnet restore
$ dotnet run
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;HTTP запрос выполняется асинхронно.&lt;/p&gt;
&lt;div class=&quot;literal-block-wrapper docutils container&quot; id=&quot;id2&quot;&gt;
&lt;div class=&quot;code-block-caption&quot;&gt;&lt;span class=&quot;caption-text&quot;&gt;Program.cs&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;highlight-csharp&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Net.Http&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Net.Http.Headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Threading.Tasks&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ConsoleApplication&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Program&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;MainAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Wait&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Task&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MainAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HttpClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DefaultRequestHeaders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Accept&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Clear&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DefaultRequestHeaders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Accept&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
              &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;MediaTypeWithQualityHeaderValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&amp;quot;application/vnd.github.v3+json&amp;quot;&lt;/span&gt;
              &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DefaultRequestHeaders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;quot;User-Agent&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;quot;.NET Foundation Repository Reporter&amp;quot;&lt;/span&gt;
          &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

          &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stringTask&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetStringAsync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&amp;quot;https://api.github.com/orgs/ustu/repos&amp;quot;&lt;/span&gt;
          &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

          &lt;span class=&quot;kt&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stringTask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;Console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Результат выполнения программы.&lt;/p&gt;
&lt;div class=&quot;highlight-bash&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;$ dotnet run
Project net &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;.NETCoreApp,Version&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;v1.1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; will be compiled because inputs were modified
Compiling net &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; .NETCoreApp,Version&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;v1.1

Compilation succeeded.
    &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; Warning&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;s&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt; Error&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;s&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;

Time elapsed &lt;span class=&quot;m&quot;&gt;00&lt;/span&gt;:00:01.0363043

&lt;span class=&quot;o&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;:25028386,&lt;span class=&quot;s2&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;urfu_sphinx_theme&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;full_name&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;ustu/urfu_sphinx_theme&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;owner&amp;quot;&lt;/span&gt;:&lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;log&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;in&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;ustu&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;id&amp;quot;&lt;/span&gt;:9111291,&lt;span class=&quot;s2&quot;&gt;&amp;quot;avatar_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://avatars0.githubusercontent.com/u/9111291?v=4&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;gravatar_id&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/users/ustu&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;html_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://github.com/ustu&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;followers_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/users/ustu/followers&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;following_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;github.com/users/ustu/following{/other_user}&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;gists_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/users/ustu/&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;gists{/gist_id}&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;starred_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/users/ustu/starred{/owner}{/repo}&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;su&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;bscriptions_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/users/ustu/subscriptions&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;organizations_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;://api.github.com/users/ustu/orgs&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;repos_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/users/ustu/repos&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;eve&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;nts_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/users/ustu/events{/privacy}&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;received_events_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;api.github.com/users/ustu/received_events&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;type&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;Organization&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;site_admin&amp;quot;&lt;/span&gt;:false&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;private&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;:false,&lt;span class=&quot;s2&quot;&gt;&amp;quot;html_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://github.com/ustu/urfu_sphinx_theme&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;description&amp;quot;&lt;/span&gt;:null,&lt;span class=&quot;s2&quot;&gt;&amp;quot;fork&amp;quot;&lt;/span&gt;:fals
e,&lt;span class=&quot;s2&quot;&gt;&amp;quot;url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/repos/ustu/urfu_sphinx_theme&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;forks_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;.com/repos/ustu/urfu_sphinx_theme/forks&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;keys_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/repos/ustu/urfu_s&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;phinx_theme/keys{/key_id}&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;collaborators_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/repos/ustu/urfu_sphinx&lt;/span&gt;
&lt;span class=&quot;s2&quot;&gt;_theme/collaborators{/collaborator}&amp;quot;&lt;/span&gt;,&lt;span class=&quot;s2&quot;&gt;&amp;quot;teams_url&amp;quot;&lt;/span&gt;:&lt;span class=&quot;s2&quot;&gt;&amp;quot;https://api.github.com/repos/ustu/urfu_sphi&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Пользуйтесь, радуйтесь, пишите на том, что вы любите.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
</content>
  </entry>
</feed>
