Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Converting a .NET application to .NET Core (formerly DNX)

June 4, 2016
Andrew Male
Related topics:
.NETLinux
Related products:
Red Hat Enterprise Linux

Share:

    In my first .NET core post, I set out on a journey to conquer the new world of .NET Core (formerly DNX) on Red Hat Enterprise Linux (RHEL). In my ignorance I believed I would do a short post on firing up RHEL, installing .NET Core, and then converting an application from .NET to .NET Core before adding it as a build job to a new TeamCity instance. The best laid plans seem to be the ones that get me closest to throwing my computer out the window, and Part 1 stands as a comedy of my errors. With all of that sorted, however, it is time to finish the job and start working with .NET Core on RHEL. (RHEL is now available at no cost for developer use! You can download it here.)

    The Goals (A Review)

    Just to go over our goals one more time...

    • Create a functioning VM on my local machine with RHEL 7.2 and Windows Hyper-V
    • Install Visual Studio Code
    • Install .NET Core
    • Convert a simple .NET project to work on .NET Core
    • Install TeamCity
    • Create a TeamCity Build Job for the .NET project

    My Project

    I spent some time deciding what project I would try converting to .NET Core, hoping to strike a balance between something with more than a ‘Hello, World’ output, but not so complex as to be an entire application. My search ended with an experimental C# library I began working on a year ago and neglected to finish. The framework has been partially constructed in three different languages (C#, PHP, and C++), and was put together enough that I could see if building it as a library was reasonable with .NET Core.

    Step 1: The project.json File

    The theory behind .NET Core is that you shouldn’t have to do too much to convert a project. Plop down a project.json file, run the dotnet restore and dotnet run commands, and in a perfect world, you should be finished. Fresh off my battle with setting up .NET Core, I dove in and grabbed the project.json from the “hello” project, and placed it inside the root directory of my framework’s C# folder.

    Step 2: Restore/Run

    Thanks to my work in part 1, the ‘restore’ command worked beautifully. All of the dependencies I didn’t realize I required were pulled onto the machine via NuGet and made available to the project. The ‘run’ command wasn’t as uneventful. ‘Run’ presented me with a few errors, mostly pointing to my use of the Environment.OSVersion property.

    Step 3: Code Adjustments

    One of the more frustrating parts of the process was dealing with the problem of missing Environment.OSVersion. It took a bit of searching to find a relevant issue on the dotnet core GitHub. The issue explains their decision to remove the property and its enumerations (it seems they feel that targeting specific versions of operating systems is a bad idea). I can’t say how many instances of this type of breaking change there are or will be with .NET Core, but hopefully, moving forward, they are well documented for people looking to move their codebases into .NET Core.

    Regardless, thanks to the issue, I then had an idea of the problem and could devise a solution. For this framework, the purpose of the OSVersion usage was simply to help determine if the code was running on Windows or not, so I chose to replace the property with simply comparing the DirectorySeparatorChar against the typical Windows value (“\”) to make the determination.

    Step 4: A project.json Adjustment

    Now that I’d sorted the codebase to not use the missing property, I tried the dotnet run command again, only to be greeted with a new compilation error:

    error CS5001: Program does not contain a static 'Main' method suitable for an entry point

    Thankfully this made more sense to me, and I realized the “hello” application I’d copied the project.json from was actually intended to create an executable, whereas this project was meant to be a library (dll). I went back into the project.json and immediately noticed the following line:

    “emitEntryPoint”: true

    Without even looking, I figured it was worth giving a try, and changed the value to be false. Another attempt at ‘run’ produced a successful build (albeit with warnings from my incomplete code).

    Step 5: Install TeamCity and Make a Build Job

    At this point, I had finally overcome my relearning jitters. I was able to easily go through the TeamCity installation:

    • Download and install Java JRE 8u92 & JDK 8u92
    • Download and install TeamCity using the instructions
    • Start TeamCity by running the $TCPATH/bin/runAll.sh script
    • Access and configure TeamCity at http://localhost:8111/

    All that remained was to create a build job that would call dotnet restore and dotnet run whenever an update was pushed to the master branch of my framework’s repository. To say it was refreshing to have these final parts go smoothly is an understatement.

    Conclusion

    It was a much longer and tougher process than I think I’d imagined, but the satisfaction gained from making it through and achieving my goals was reward enough. As I stated before, I hope (and am quite sure) that more documentation will be added while .NET Core matures to help catch things such as my OSVersion misstep. Still, the system shows a lot of promise for helping teams expand their capabilities into the Linux/BSD world without having to do a complete rebuild of their codebase.

    Caveat

    I purposefully left out information regarding the way I made things like TeamCity available to run on my VM. I am aware of how little I know with regard to securing a Linux system, so I find it hard to believe I came even close to following appropriate procedure when installing TeamCity, Java, and even .NET Core. Be careful of these things the way you would anything else. Making them available to the world likely provides bad consequences.

    For additional information and articles on .NET Core visit our .NET Core web page for more on this topic.


    Andrew Male

    Andrew Male (@AndyM84) is a senior engineer at an enterprise development company in Boston, MA. Andrew has been programming from a young age and is entirely self-taught. He has spent time in many corners of the programming world, including game/VR work, agency work, and teaching development to students and adults alike. He spends most of his time working on architecture design and pursuing his favorite hobby—physics.

    Last updated: January 19, 2023

    Recent Posts

    • Unleashing multimodal magic with RamaLama

    • Integrate Red Hat AI Inference Server & LangChain in agentic workflows

    • Streamline multi-cloud operations with Ansible and ServiceNow

    • Automate dynamic application security testing with RapiDAST

    • Assessing AI for OpenShift operations: Advanced configurations

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue