Documentation

    Table of Content
    • CodePorting.Native Product Family
      • CodePorting.Native Cs2Cpp
        • Getting Started
          • Product Overview
          • Installation
          • Licensing
          • How to use CodePorting.Native Cs2Cpp
            • How to Use Command line to port and build Projects
            • How to Use GUI to port and build Projects
        • Developer Guide
          • Porting Simple C# Projects
            • Porting Simple Console Application
            • Porting Simple Library
            • Porting Simple NUnit Test
          • Porting Dependent C# Projects
            • Porting Dependent Console Application
            • Porting Dependent Library
            • Porting Dependent NUnit Test
          • Porting Complex C# Projects
            • How to Convert Complex C# Console Application to C++
            • How to Convert Complex C# Library to C++
            • How to Convert Complex C# NUnit Test to C++
          • What Converts to What
            • Abstract Classes
            • Auto Properties
            • Break Statements
            • Class Constructors
            • Continue Statements
            • Delegates
            • Do While Statemetns
            • Enums TypeCast
            • Enums
            • Events
            • Exceptions
            • Expected Exceptions
            • Finalizers
            • For Statements
            • ForEach Statements
            • Generic Classes
            • Generic Delegates
            • Generic Interfaces
            • Generic Methods
            • Generic Structs
            • If Statements
            • Indexers
            • Lambda Expressions
            • Methods
            • Nested Classes
            • Properties
            • Return Statements
            • Simple Class
            • Simple Interface
            • Simple Struct
            • Simple Test
            • Standard TypeCast
            • Static Class
            • Static Constructor
            • Static-Methods
            • Static Properties
            • Switch Statements
            • Test with Setup Methods
            • Throw Statements
            • Try Catch Finally Statements
            • Try Catch Statements
            • Try Finally Statements
            • Var Expressions
            • Virtual Methods
            • While Statements
          • CodePorting Native Cs2Cpp Attributes
          • CodePorting Native Cs2Cpp Configuration File
            • CodePorting.Native Cs2Cpp Configuration File Structure
            • Attributes in Configuration file
            • Configuration file Nodes
            • Configuration file Options
          • Memory Management Model
            • Using aliasing constructor to create a smart pointer
          • Cmake Support
          • Limitations and Bugs
            • Porter Limitations and Bugs
            • Library Limitations and Bugs
            • Cpp Code Injection
        • Release Notes
          • 2020
            • CodePorting.Native Cs2Cpp 20.11
            • CodePorting.Native Cs2Cpp 20.12
            • CodePorting.Native Cs2Cpp 20.10
            • CodePorting.Native Cs2Cpp 20.9
            • CodePorting.Native Cs2Cpp 20.8
            • CodePorting.Native Cs2Cpp 20.7
            • CodePorting.Native Cs2Cpp 20.6
            • CodePorting.Native Cs2Cpp 20.5
            • CodePorting.Native Cs2Cpp 20.4
            • CodePorting.Native Cs2Cpp 20.3
            • CodePorting.Native Cs2Cpp 20.2
            • CodePorting.Native Cs2Cpp 20.1
          • 2021
            • CodePorting.Native Cs2Cpp 21.1
          • 2018
            • CodePorting.Native Cs2Cpp 18.9
            • CodePorting.Native Cs2Cpp 18.9.1
            • CodePorting.Native Cs2Cpp 18.10
            • CodePorting.Native Cs2Cpp 18.11
            • CodePorting.Native Cs2Cpp 18.12
          • 2019
            • CodePorting.Native Cs2Cpp 19.1
            • CodePorting.Native Cs2Cpp 19.2
            • CodePorting.Native Cs2Cpp 19.3
            • CodePorting.Native Cs2Cpp 19.4
            • CodePorting.Native Cs2Cpp 19.4.1
            • CodePorting.Native Cs2Cpp 19.5
            • CodePorting.Native Cs2Cpp 19.6
            • CodePorting.Native Cs2Cpp 19.7
            • CodePorting.Native Cs2Cpp 19.8
            • CodePorting.Native Cs2Cpp 19.9
            • CodePorting.Native Cs2Cpp 19.10
            • CodePorting.Native Cs2Cpp 19.11
            • CodePorting.Native Cs2Cpp 19.12

    What's on this Page

      • Overview
      • Supported Options
    1. Home
    2. CodePorting.Native Product Family
    3. CodePorting.Native Cs2Cpp
    4. Getting Started
    5. How to use CodePorting.Native Cs2Cpp
    6. How to Use Command line to port and build Projects

    Overview

    CodePorting.Native Cs2Cpp provides a command-line option to convert C# code into equivalent C++ code. The input for the CodePorting.Native Cs2Cpp is a C# project and a configuration file that contains options governing different aspects of the conversion process. The output of CodePorting.Native Cs2Cpp a set of .cpp and .h files and a set of Cmake configuration files that can be used to generate project files and makefiles and build the sources for one of the supported platforms/compilers.

    Conversion is performed on a per-project basis, thus in order to convert a multi-project C# solution each project has to be converted separately. If the C# project to be converted has a dependency on another C# project, the dependent-upon project has to be converted first. Then, when converting the dependent project, the information about its dependencies has to be specified in the configuration file that is passed to the Porter along with the project. The general rule is that projects should be converted in the order from the least dependent to the most dependent.

    Porter comes with a default configuration file, which contains default values for all options. Porter uses default configuration file if user does not specify an alternative configuration file. Usually default configuration file is a good option for the simplest projects that have no dependencies. However, for more complex projects and/or projects that depend on other projects, configuration file has to be created and passed to the Porter. 

    Porter executable //CsToCppPorter.exe// file for command-line auto porting option is located in //bin/porter// directory in Porter installation directory.

    Usage: CsToCppPorter.exe   <output_dir>

     Denotes a list of options that control different aspects of conversion process.

     A path to the .csproj file of the C# project to be converted. This can be a full path or a path relative to the current directory.

    <output_dir> A path to the directory where Porter will put the generated files. This can be a full path or a path relative to the current directory. If the specified directory does not exist Porter will create it.

        >CsToCppPorter.exe -c C:\SimpleConsoleApp\SimpleConsoleApp.porter.config C:\SimpleConsoleApp\SimpleConsoleApp.csproj C:\output
    

    Supported Options

    -h, ~-~-h, /h, /? Prints short instruction of how to use Porter from command line and a list of command line options with short description.

    -q Prevents output of percent values indicating the conversion progress to the console window.

    -c  Specifies a configuration file containing the conversion options to be applied when converting the C# project.  is a path to the configuration file; this can be a full path or a path relative to the current directory. If this option is not specified Porter will use default configuration file //porter.config// located in the Porter’s home directory.

    -H  Sets a Porter home directory used by Porter when resolving paths. Normally this option should not be used.

    -a Instructs Porter to run in Analysis mode, which means that Porter processes the input project and configuration file, generates warning and error messages (if any) just as in normal mode, but does not generate the output files. This may save some time during debugging of the C# project to be converted or a configuration file.

    -g  Specifies a name of the configuration (e.g. Debug, Release etc.) defined in input C# project to be used by Porter. In order to properly convert the project, Porter needs to know project settings specified under particular configuration. This option tells Porter which configuration to read the settings from. The input C# project must have at least one configuration defined, otherwise conversion fails. If this option is missing, a configuration with name “Debug” is used by default.

    -w0 Specifies that the Porter should always return 0 despite the number of errors or warnings that occurred during porting. This behavior is default. This option is inconsistent with -w1 and -w2.

    -w1 Specifies that the Porter should return 1 in case if an error (but not warning) occurs during porting. If no errors occurred during porting the return value will be 0. This option is inconsistent with **-w0 **and -w2.

    -w2 Specifies that the Porter should return 1 in case if an error or warning occurs during porting. If neither errors nor warnings occurred during porting, the return value will be 0. This option is inconsistent with -w0 and -w1.

    -d0 Specifies that all pre-processor directives encountered in C# code should not be inserted in the output C++ code as comments. Also see option -d1. This option is inconsistent with -d1.

    -d1 Specifies that all pre-processor directives encountered in C# code should be inserted to the resulting C++ code as comments. This may be helpful when debugging the conversion. This behavior is default. This option is inconsistent with -d0.

    -m  Specifies if Porter should use a single thread (when # false) or multiple threads (when # true) when porting a project. If this option is not specified, the default value ‘true’ is used. When the option to use multiple threads is specified, Porter will use up to as many threads as the number of CPUs.

    -d  Defines a variable with the specified name which can be referred to in node in Porter configuration file. Refer to Porter configuration documentation for further details.

    -st Instructs Porter to generate only Cmake configuration files as its output without C++ sources.

    -o # Assigns a value to the Porter configuration option named . A value specified by this option takes precedence over the value specified in the input configuration file.

    -O Instructs Porter to put the output files and directories directly to the directory specified by <output_dir> command line argument. By default if this option is omitted, Porter will create a sub-directory under <output_dir> named <project_name>_Cpp (where <project_name> is the name of the input C# project) and will put the output files and directories in it.