Any Developer, Any App, Any Platform: Get Access To Products and Resources To Help You Code. Join Today. It's Free
Any Developer, Any App, Any Platform: Get Access To Products and Resources To Help You Code. Join Today. It's Free
237
Get More Refcardz! Visit DZone.com/Refcardz
ANY DEVELOPER, ANY APP, ANY PLATFORM RED HAT ENTERPRISE LINUX 7 SERVER (64 BIT)
When .NET made its debut in 2002, it supported subscription-manager list --available
multiple languages, including C\# and Visual Basic (get the Pool Id to be used in the next step)
subscription-manager attach --pool=<Pool Id>
(VB). Over the years, many languages have been added
subscription-manager repos --enable=rhel-7-server-dotnet-rpms
to the .NET Framework. Because .NET Core is a new yum install scl-utils
development effort, language support must be re-in yum install rh-dotnet20
echo ‘source scl_source enable rh-dotnet20’ >>~/.bashrc
This refcard will guide you along the path to being scl enable rh-dotnet20 bash
productive using .NET Core on Linux, from installation UBUNTU 14.04 / LINUX MINT 17 (64 BIT)
to debugging. Information is available to help you
find documentation and discussions related to .NET sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.
Core. An architectural overview is presented, as well trafficmanager.net/repos/dotnet-release/ trusty main" > /
etc/apt/sources.list.d/dotnetdev.list'
as tips for using the new Command Line Interface sudo apt-key adv --keyserver apt-mo.trafficmanager.net
(CLI). Building MVC web sites, RESTful services and --recv-keys 417A0893
standalone applications are also covered. Finally, sudo apt-get update
manager to retrieve the dependencies for your project. For When listing your dependencies in the *.csproj file, you
example, you may use npm when developing in node.js in must also specify the version of the library. For example,
order to fetch your dependencies. <PackageReference Include="Microsoft.AspNetCore.All"
Version="2.0.0" />.
Likewise, the dotnet restore command is the equivalent
in .NET Core; it is a package manager. When executed, In this particular example, we are locking our
it will use your configuration to locate and retrieve dependency to version 2.0.0. You can search nuget.
any dependent libraries (and their dependencies, etc.) org to find versions of libraries. Or, if you are using an
for your project. The configuration that guides the editor with Intellisense such as Visual Studio or Visual
dotnet restore command is made up of two parts: The Studio Code, it will allow you to choose from a list of
*.xxproj file (e.g. helloworld.csproj), which lists your valid versions.
dependencies, and the NuGet configuration file, which
directs from where to fetch the dependencies. WHAT DOES DOTNET BUILD DO?
The NuGet configuration file, NuGet.Config, is located at When you run dotnet build, or if you run dotnet run and
~/.nuget/NuGet/NuGet.Config. This file contains a list
it automatically creates a new binary, by default it will
of endpoints used when fetching dependencies. The create a DLL at the following location:
endpoints can point to anywhere that can be reached
./bin/[configuration]/[framework]/[binary name]
from your machine, including the internet and internal
storage. The following lists the contents of the default
NuGet.Config file:
Using the HelloWorld application in a directory labeled
"helloworld" as an example, running dotnet build would
<configuration> result in:
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/ ~/helloworld/bin/Debug/netcoreapp1.0/helloworld.dll
index.json" protocolVersion="3" />
</packageSources>
</configuration>
This DLL is what is known as a Portable App, meaning it
can run on any system that has .NET Core installed.
You can add endpoints; they are searched in order. Copying this DLL to another system -- whether Linux,
You do not need to point to nuget.org. For example, MacOS or Windows -- means it can be run on that
you can use daily builds of .NET Core (obviously not
recommended for production) by switching to myget.org.
system using the dotnet run command. This powerful
For example, https://dotnet.myget.org/F/dotnetcore/api/
feature allows you to write once, run anywhere, as long
v3/index.json.
as .NETCore is installed on the target system.
You can override the default NuGet.Config file by storing a
project-specific copy in your project’s root directory. For What if .NET Core is not installed on the target system?
example, if your project is located at ~/src/mvc, you can In that case, you can build a self-hosting app, meaning
create the file ~/src/mvc/NuGet.Config and it will be used you can compile it for the target operating system, then
before the default file. distribute it. To run it, it does not need .NET Core installed
on the target system; the dotnet publish command will
WHERE ARE THE DEPENDENCIES STORED? copy all the necessary bits (libraries) into the target build
By default, all dependencies are stored locally on your directory. You need only to copy the contents of that
machine at ~/.nuget/packages/. You can override this directory to another system and it will execute.
by specify a path in the environment variable **DOTNET_
PACKAGES** before running the dotnet restore command. Note that you can build for any OS from any OS. This
As the dependencies are downloaded, a file is created powerful feature means you can build standalone
(or updated if it already exists) in the root directory of applications for Windows from Linux, for MacOS from
your project. The file, obj/project.assets.json, contains Windows, etc.
a list of your dependencies. This list snapshot in time is
used to when you run the dotnet restore command. You The details of creating a standalone application are
can delete this file, but you’ll need to run dotnet restore covered later in this refcard.
again before your next compile. The file is not needed to
HOW TO CREATE A BASIC ASP.NET MVC WEBSITE
run your application, only to build it.
The dotnet net new command has options to allow you to
build an ASP.NET MVC website. This is similar to using
DEPENDENCY VERSIONS
Visual Studio to create a new website and choosing the
You can now view the basic ASP.NET MVC website at asp-src-include
Include files with the ability to use globbing, e.g. asp-
http://localhost:5000. src-include="/scripts/**/*.js".
SOME COMMON TAG HELPERS 2. On the Linux VM, install the cross-platform debugger
TAG HELPER DEFINITION from Microsoft, CLRDBG. Use the following command,
Used to create the HTML for a property. For example, which reads a bash script from GitHub and executes
asp-for <input asp-for="AlbumTitle" /> will create an it on your VM, to install the debugger into the
input area for the model property AlbumTitle. directory ~/clrdbg:
Defines which action will be used in the current a. curl -sSL
asp-action
controller.
[*https://raw.githubusercontent.com/Microsoft/MIEngine/
asp-all-route-data Allows you to append query string information to a URL.
getclrdbg-release/scripts/GetClrDbg.sh*](https://raw.
asp-controller Determines which Controller will be used githubusercontent.com/Microsoft/MIEngine/getclrdbg-release/
scripts/GetClrDbg.sh)
asp-fragment Allows you to specify a page fragment, e.g. "TOC". | bash /dev/stdin vs2015u2 \~/clrdbg
4. Share a folder/directory between the Windows host Which testing tool: NUnit, xUnit, etc. An entry
"testRunner" string here also indicates that this is a test project (i.e.
and the Linux > machine
created with dotnet new --type xunittest).
a. Create a shared folder on the Windows host A JSON object that lists the dependencies used
"dependen- JSON
called "shared". by the project. These are downloaded when
cies" object
dotnet restore is run.
b. Create a directory on the Linux machine called "/ JSON Defines the tools available, including making the
"tools"
shared". object dotnet ef command available.
Previously "compilationOptions", this is where
c. If you are using Vagrant, add the following line "buildOp- JSON compile-time options are set. For example, "emi-
to your Vagrantfile: config.vm.synced_folder "\\ tions" object tEntryPoint" can be set to true or false to create
shared", "/shared" an executable or DLL.
Allows you to establishing different project con-
5. Create the launch options XML file and add it to your "configura- JSON
figurations such as Release, Debug, Staging, etc.
tions" object
project in Visual Studio. Call it "OffRoadDebug.xml": This setting is available to your code.
d. Debug.MIDebugLaunch /Executable:dotnet/
To start, create a portable app by running dotnet new in
OptionsFile:C:\\<path-to-file>\\OffRoadDebug.xml
a directory named selfhost.
THE .CSPROJ FILE Now, instead of dotnet run or dotnet build, use the
following command:
The project.json file determines everything from
dependencies to build options to which tools are
dotnet publish -r Release -c win10-x64
used, and much more. Here’s a list of some of the
settings available:
This will create a self-hosting app at bin/Release/
DATA netcoreapp2.0/win10-x64/publish. Copy the contents of
NAME DEFINITION
TYPE this directory to a Windows 10 machine and you can run
"name" string The name of your application. the created selfhost.exe -- no .NET installation necessary.
The "win10-x64" is what is known as a Runtime Identifier
(RID). This value instructs the compiler to build for a today, but it is the future of .NET. Because you can work
specific operating system -- in this case, Windows 10, in any OS—MacOS, Windows or Linux—you can easily
64-bit. A list of values can be found at (https://docs. switch between environments and remain productive.
microsoft.com/en-us/dotnet/articles/core/rid-catalog). Further, you can now use your .NET development skills
to work with and on open source software. This is the
dotnet restore
dotnet build rhel.7.2-x64
future, and the future is now.
REFCARDZ: Library of 200+ reference cards covering the latest tech topics
COMMUNITIES: Share links, author articles, and engage with other tech experts
JOIN NOW
Copyright © 2017 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or SPONSORSHIP OPPORTUNITIES
transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
[email protected]