.NETCoreを使ってUbuntuでC#を動かそう!

皆さんこんにちは!
C#いいですよね、とても書いていて気持ちいい言語だと思います

現在当サークルのDiscord会議で稼働しているアイドル、TUSBちゃんはC#で作られたBOTです。

しかしC#は今までwindowsでしか動きませんでした。
もちろんMonoやWineなどのサードパーティのものを使えば動かすことはできましたが、公式ではありません。
Xamarinなんかもありましたが使い勝手はいまいち・・・

そこで最近出てきた.NETCoreを使ってC#やF#で書いたソフトウェアを動かそうという魂胆です。
.NETCoreの詳しい解説は割愛しますので、気になる人は調べてみてくださいな。

 

今回の環境

  • Ubuntu 16.0.4 64bit
  • .NETCore 1.0.4
  • VisualStudio2017 Community(アプリケーション開発用)

 

インストール


まずパッケージを最新の状態にします。

sudo apt-get update
sudo apt-get upgrade

次に、.NetCoreのリポジトリとAPTキーを追加する

sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893

もう一回アップデート

sudo apt-get update

最後にパッケージとしてインストールする。

sudo apt-get install dotnet-dev-1.0.4

以上で.NetCoreのインストールは終了です。続いて、Windowsで何かアプリケーションを作成してみます。

 

アプリケーション作成


今回はwindows10にて、VisualStudio2017を使いC#アプリケーションを開発してみます。
VisualStudioの導入方法などは割愛しますので、別途調べてください。

ファイルより、新規作成をクリックしプロジェクトを選択します。
図のようにVisual C#から「コンソールアプリ (.NET Core)」を選択しプロジェクトの名前を入れたらOKを押します。※コンソールアプリ(.NET Framework)を選ばないよう注意

 

今回はCoreTestという名前で作成しました。
すると以下のようなコードになっていると思います。

using System;
namespace CoreTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

ではこのプログラムをビルドしてみましょう。
上側にあるDebugとなっているコンボボックスをReleaseに変えて、ビルドタブからソリューションのビルドを選択してください。

ビルドが完成すればソフトウェアの完成です。
出来上がったソフトウェアはデフォルトでは

C:\Users\ユーザー名\Documents\visual studio 2017\Projects\CoreTest\CoreTest\bin\Release\netcoreappx.x

名前を付けたプロジェクト名.dll(今回はCoreTest.dll)として保存されていると思いますので、各自見つけてください
そうしたら、このフォルダの中に入っているソフトウェアを含めたファイル全てをUbuntuに何らかの方法で送りましょう。
ftpでもオンラインストレージを経由させてwgetコマンドを使用してもOKです。
Ubuntuのどこかのフォルダに保存してください。

そうしたら、cdコマンドを使い、ソフトウェアファイルらを保存したフォルダに移動し、以下のコマンドを入力することでソフトウェアが実行されます。

※ソフトウェアがCoreTest.dllの場合
dotnet CoreTest.dll

いかがでしたでしょうか。Hello World!が表示されれば成功です。
お疲れ様でした。

One Response to “ .NETCoreを使ってUbuntuでC#を動かそう! ”

  1. From being one of the most rewarding jobs a few years back, the office of the
    governor in Nigeria has suddenly become the most vilified if not the most hazardous job, possibly in the universe.
    Across the federation, the story, with only few
    exceptions, is a familiar one: state executives being openly
    derided for lack of imagination in the face of the problems currently plaguing the states
    under them; others have all manners of expletives hurled at them almost on daily basis for sundry – even if unproven – crimes of
    heist. There cannot be a worse time to be a governor.

    If the announcement last week of release of the sum of N243.79bn second tranche of the Paris Club was designed to calm troubled waters, it has merely ushered in a new wave of restiveness.
    In some states, workers and pensioners, many of them owed several months of salaries and pensions have
    since declared war on their governors whom they
    accuse of embezzlement even when the funds were yet to hit the accounts!
    Whereas the rumblings fit into the pattern of the general disenchantment in which the governors continue to present as soft
    targets, what the latest development has done is open a new
    chapter in which legion of angry, frustrated civil servants have
    moved beyond dinghy prayer rooms to taking their cases
    to the streets.

    As they say, we have moved full circle. From
    the fruitless supplications of the past years, the angry horde, now pressed
    to the barricades, seems poised to challenge the gubernatorial
    fiefdoms of our excellences over the fiscal direction, if not discretion of their
    states. Deploying an adroit combination of misinformation, propaganda, blackmail and crude intimidation as weapons of choice, there is, for now,
    no stopping the agitators in their new found power.
    Clearly, if the unfolding developments are
    any measure of the anger and discontent in the land – a rage which although is driven largely by the failure of most states to meet up
    with their wages and pensions obligations, is actually a reflection of the rising
    frustrations over the general state of the economy – the portents must be deemed as frightening as they come.

    Talk of a new day and season – a period ruled by rage and unreason. If it comes to our Excellencies as the dawn of a new,
    albeit rude awakening, it seems increasingly clear that cold rational arguments matched
    by unassailable facts and figures would hardly suffice to calm the nerves of the angry throng.
    As many governors are sooner finding out, the current season brooks no such luxury.

    Not even the publication of the amount due to each state in the
    latest bailout expected to temper the expectations of the citizens across the
    states has done the trick; instead, it has merely caused a fresh burst of unrestrained adrenalin. How could
    anyone have imagined the governors so terribly boxed in between the rage
    of the rabble and the feigned righteousness of their emergency,
    latter day saviours – standing any chance? That
    is how serious things have become.

    No one cares – or appears to be – about the fiscal anomaly of the so-called Paris Club ‘overpayment’ in a supposedly constitutional
    environment; or even the criminally flawed book-keeping and fiscal practices that brought the funds about.
    Or where the piggy bank has been all these while and who
    held charge. It is sufficient that the billions, warehoused
    in some opaque, possibly dormant account now pressed into service, are working magic in what is deemed as heroic act.
    Permanently foreclosed is the debate about the refunds whose
    provenance best emblematizes the egregious absurdity in our public
    finance!

    We can, for the moment, forgo the hard discussions on the
    future of the economy; the structural distortions
    under which some 30 out of 36 states have practically turned leeches; the question of how
    the leviathan comes to take a disproportionate chunk of the pie which
    it neither needs nor could wisely gobble down. As to worries
    about the sustainability of a political economy hung on bailouts, all of
    these would come later. It is simply taken that a share of the magic potion, no matter
    how small, would be just fine, if not in the treatment but
    at least in the management of the endemic, structural disease!

    But then, as we would be finding out – sooner than later – that whereas an obsession with placebo might have some therapeutic value, it means
    pretty little if the ailment is not attacked at the roots.
    For no matter how much we laud the Santa Claus federal government for coming to the aid of the states
    in their hour of distress, an early relapse of
    the ailment, as it seems inevitable in this matter, will in the final count
    leave everything undone.

    Secondly, the governors might be guilty as hell of the charges against them and
    so deserving of the scorn being daily heaped on them by the
    angry folks; they are as much the rest of us victims of the warped structure which allows
    the central government to draw 52 percent of the pie leaving the crumbs for the 36 states to share.
    A picture of how unwieldly the federal government has become is the report only last
    week of how some unnamed agencies managed to withhold $793,
    200,000 (about N249.7 billion) of public funds in clear breach of the Treasury Single Account (TSA) policy.
    We are here talking about a fund that is a little more than the payout on the second tranche of the Paris Club refunds being allegedly shuffled around by unscrupulous
    bankers in collusion with corrupt government officials!

    Let’s face it: the country is in for a long dark night. This is where
    I hate to disappoint the angry throng. For pray as they might, the possibility of
    oil prices hitting the roof sometimes soon seems for now,
    far-fetched; not even the modest pace of recovery can be guaranteed in the context of the tenuous peace pervading in the Niger Delta.
    So they had better brace up for life after Paris Club.
    The prospect of a life tempered by realism must be somewhat frightening
    from the look of things. But even worse is the alternative – a life of unrealizable expectations.
    It is a tough one that is.

    But then, who says all hopes are lost? Is the saying
    no longer true that labour creates the wealth?
    How about getting on with the job?

コメントを残す